Reputation: 683
When binding on the 'keydown' event on a tinyMCE editor instance, calling preventDefault() on the event does not prevent the default behavior in the editor. For example, when capturing the ENTER key being pressed with the following code:
tinymce.init({
selector: 'textarea',
setup: function (editor) {
$(editor).on('keydown', function (event) {
if (event.which == 13) {
alert('enter pressed');
event.preventDefault();
}
});
}
});
TinyMCE still inserts a line break. How can I override this behavior?
Upvotes: 3
Views: 3042
Reputation: 21666
Change
if (event.which == 13) {
alert('enter pressed');
event.preventDefault();
}
to
if (event.which == 13) {
alert('enter pressed');
event.preventDefault();
event.stopPropagation();
return false;
}
Upvotes: 5