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

Support is currently Offline

Official support hours
Monday to Friday
09:00 - 17:00 Europe/London (BST)

Please create a new Ticket and we will get back to you as soon as we can.

#100602 How to set focus with Javascript?

Posted in ‘Editor’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Latest post by Viperfish on Wednesday, 24 July 2019 04:00 BST

Viperfish
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

Viperfish
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.