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?
Change
if (event.which == 13) {
alert('enter pressed');
event.preventDefault();
}
to
if (event.which == 13) {
alert('enter pressed');
event.preventDefault();
event.stopPropagation();
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With