I'm using TinyMCE for a textarea on a page but it doesn't play nice in the tabbing order of the other elements.
I can use the following code to capture when I tab out of the first element:
$('#title').live('keypress', function (e) {
if(e.keyCode == 9) {
alert('tabbed out');
}
});
How can I set the focus to a TinyMCE editor?
Finally found an answer... use the command:
For my purposes, 'id_of_texterea' was "description", ie
In the form element that preceded my textarea, I added the execCommand above to the element's "onblur" action.
This works for me (TinyMCE version 4.7.6):
I use the following function to focus the editor with thinyMCE This is using jQuery, but would be easy to strip this out and use
document.querySelectorAll()
. Use babel if you need this in es5.The editorContainer is any element surrounding the tinyMCE textarea, e.g. a div with id 'text-container' you could call
focusEditor($('#text-container'))
or in ReactfocusEditor(React.findDOMNode(this))
Looks like for TinyMCE 4 a few of these solutions no longer work.
// Doesn't seem to work on TinyMCE 4
// Didn't work
What works for me
// Works great in Chrome, but not at all in Firefox
// Add this so Firefox also works
What actually works is setting an option in the
configfile
(or jquery file) This option enables you to auto focus an editor instance. The value of this option should be an editor instance id. The editor instance id is theid
for the original textarea or<div>
element that got replaced.Example of usage of the
auto_focus
option:For Auto focus in tinymce the documentation first example says that - https://www.tinymce.com/docs/configure/integration-and-setup/#auto_focus
This works for me in TinyMCE Version
4.7.6