You need to be logged in to post in the forum - Log In

An active JCE Pro Subscription is required to post in the forum - Buy a Subscription

  1. Viperfish
  2. JCE Editor
  3. Wednesday, 24 July 2019
Hi JCE,

Using javascript how do I set focus on the JCE editor ?

As a bit of background, I'm building a custom component with nested comments. The comment form is loaded in a hidden div and moved (using jQuery .append) to the appropriate container when a reply button is pressed. The field is re-initialised with the following code and it all works fine.

tinyMCE.execCommand('mceRemoveControl',false,'jform_comment');
tinyMCE.execCommand('mceAddControl',false,'jform_comment');


I just can't set the focus on the JCE editor after it's displayed. I've tried the following.
tinymce.activeEditor.focus();
tinymce.EditorManager.get('jform_comment').focus();
tinyMCE.get('jform_comment').getBody().focus();
tinyMCE.get('jform_comment').focus();


I'm sure I'm missing something really simple? Thanks in advance
John
Accepted Answer Pending Moderation
To answer my own question, the answer is

tinyMCE.get('jform_comment').getBody().focus();


OK. I'm a doofus. I was testing these functions from the console but you can't set focus elsewhere if the focus is on the console. Works fine in code.
  1. more than a month ago
  2. JCE Editor
  3. # 1
  • Page :
  • 1


There are no replies made for this post yet.
Be one of the first to reply to this post!