Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preventDefault not working with tinyMCE keydown event

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?

like image 460
user1569339 Avatar asked Dec 19 '25 20:12

user1569339


1 Answers

Change

 if (event.which == 13) {
      alert('enter pressed');
      event.preventDefault();
 }

to

 if (event.which == 13) {
      alert('enter pressed');
      event.preventDefault();
      event.stopPropagation();
      return false;
}
like image 167
Chankey Pathak Avatar answered Dec 22 '25 11:12

Chankey Pathak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!