1

Topic: Set Focus On TinyMCE

OK so I've seen in other posts how you can set the focus using the following code:

tinyMCE.execCommand('mceFocus', false, 'mce_editor_0');

Where 'mce_editor_0' is the id of the editor.  I've tried this and nothing happens.  How do I verify that the id is 'mce_editor_0'?


Thanks,
Jim

2

Re: Set Focus On TinyMCE

I'm asking the same question!  The buggered thing doesn't work.

Init code looks like this

tinyMCE.init({
                        mode : "exact",
                        theme : "advanced",
                        plugins : "advlink,emotions,fullscreen",
                        elements : "project_note_description" //, project_long_description"
                });

focus code has look like this
tinyMCE.execCommand('mceFocus', true, "mce_editor_0");
this
tinyMCE.execCommand('mceFocus', false, "mce_editor_0");
this
tinyMCE.execCommand('mceFocus', true, "project_note_description");
and this
tinyMCE.execCommand('mceFocus', false, "project_note_description");

NONE of these gets the cursor in the little window.  HELP US!!!

3

Re: Set Focus On TinyMCE

first if you have an instance already set, there shouldn't be any reason to give it focus. Otherwise, you would pass it the id of an element (plus don't forget to give it a toolbar):

<div id="foo"><p>content</p></div>

tinyMCE.execCommand('mceAddControl', false, 'foo'
tinyMCE.execCommand('mceFocus', false, 'foo'););

4

Re: Set Focus On TinyMCE

It still doesn't work at my editors. I have 4 editors that are initialized by 2 init codes:

        tinyMCE.init({
            //language : "pl",
            theme_advanced_toolbar_location : "top",
            theme: "advanced",
            mode : "exact",
            elements : "textarea_el",
            body_id : "textarea_el=body_id_textarea",
            body_class : "textarea_el=body_class_textarea",
            plugins : "emotions",
            theme_advanced_buttons1 : "fontselect,fontsizeselect,bold,italic,underline,forecolor,emotions",
            theme_advanced_buttons2 : "",
            theme_advanced_buttons3 : "",
            width: 300,       
            height : 430,
            init_instance_callback : "myCustomInitInstance"
        });
        tinyMCE.init({
            //language : "pl",
            theme_advanced_toolbar_location : "top",
            theme: "advanced",
            mode : "exact",
            elements : "address_el1,address_el2,address_el3",
            body_id : "address_el1=body_id_address1,address_el2=body_id_address2,address_el3=body_id_address3",
            body_class : "address_el1=body_class_address,address_el2=body_class_address,address_el3=body_class_address",
            plugins : "emotions",
            //theme_advanced_buttons1 : "fontselect,fontsizeselect,bold,italic,underline,forecolor,backcolor,emotions",
            theme_advanced_buttons1 : "fontselect,bold,italic,forecolor,emotions",
            theme_advanced_buttons2 : "",
            theme_advanced_buttons3 : "",
            //width: 295,
            width: 300,           
            height : 54,
            //nowrap : true,
            init_instance_callback : "myCustomInitInstance"
        });


So, having those, how can i set focus on each of them?

5

Re: Set Focus On TinyMCE

Hi @uluru75,

  As has been stated, you need to use the command tinyMCE.execCommand('mceFocus',false,'element ID');, replacing element ID with the ID of the element TinyMCE has been applied to that you want focus set on.

  So, from your config, you have 4 elements on the page that TinyMCE is being used in.

   elements : "textarea_el",

   elements : "address_el1,address_el2,address_el3",

So, to focus on address 2, you would simply use tinyMCE.execCommand('mceFocus',false,'address_el2');

  Cheers,
  Brett

Brett Henderson
http://tinymce.ephox.com

Last edited by brett.henderson (2010-06-30 02:16:02)

6

Re: Set Focus On TinyMCE

It works perfectly, actually before was executing the command too early. Now is good.

But now how to set the cursor at the end of the previously inserted content?

Last edited by uluru75 (2010-06-29 22:56:30)

7

Re: Set Focus On TinyMCE

uluru75 wrote:

But now how to set the cursor at the end of the previously inserted content?

Anyone has solved this yet?

8

Re: Set Focus On TinyMCE

You can probably do a
tinymce.dom.selection.setNode
and then do a
tinymce.dom.selection.collapse
to get the selection you wanted.