4 Replies Latest reply on Dec 17, 2009 10:16 AM by boldoran

    <rich:editor> How to set Focus

      Hello

       

      I am trying to set the Focus on a rich:editor element.The xhtml code looks like this:

       

      <a4j:form id="form">
      ...
      
        <rich:editor  id="editor" width="750" 
                      requiredMessage="#{msg['error.inputRequired']}"
                      validatorMessage="#{msg['error.toolong']}"
                      value="#{patientenJournalBean.neuerFreitextEintrag.text}"
                      configuration="richeditor-config" />
      
      <a4j:form/>
      
      ..
      <script>
                              document.getElementById('form:editor').focus();
       </script>
      

       

      This does not work however. I belive this is related to the fact the the generated html code uses the id given to the <rich:editor> tag for a <div> element that is placed around the editor. How can I set the focus on the input part of the <rich:editor>

        • 1. Re: <rich:editor> How to set Focus
          could you check how its rendering , by checking render html code. there you can get the input field you are looking for, and then you can set focus to it by javascript
          • 2. Re: <rich:editor> How to set Focus
            ilya_shaikovsky
            1 of 1 people found this helpful
            • 3. Re: <rich:editor> How to set Focus

              Thank you for setting  me on the right track.

              tinyMCE.execInstanceCommand("mce_editor_0", "mceFocus");
              

               

              this did not work right away for me. However I found this forum entry

               

              http://tinymce.moxiecode.com/punbb/viewtopic.php?id=4561

               

              after some fiddling here is what worked:

               


              <rich:editor   id="editor" width="750"
                             value="#{backingBean.text}"
                             oninit="setTimeout( function() {
                                       tinyMCE.execCommand('mceFocus',false,'FORMID:editorTextArea');
                                       }, 1);
                             />
              
              
              editorTextArea is the id of the TextArea that is generated in the html code (check with firebug or examine html sourcecode to find it)
              • 4. Re: <rich:editor> How to set Focus

                 

                could you check how its rendering , by checking render html code. there you can get the input field you are looking for, and then you can set focus to it by javascript

                 

                I could not find an input field that I could use for this purpose in the html code. The only InputField generated is a TextArea and it has visibility hidden. I guess the editor uses some javascript magic to work directly in the html code.


                See above for a solution.