Search code examples
javascriptjquerynewlineenterquill

Quill.js: How to prevent newline entry on Enter to submit the input?


The problem:

I'm trying to create a Rich-Text Inline content-editable element with Quill.js. I'm having a hard time figuring out how to submit the body without the unnecessary newline added by the enter trigger which I want to use to submit the input.

What I tried:

 $(quill.editor.root).on('keydown', function (e) {
       if (e.keyCode === 13) {
           e.preventDefault();
           e.stopPropagation();
           submit();
       }
 });

Any ideas?


Solution

  • Quill also listens on keydown and since it's registered before your handler it will fire first. You can remove it via the keyboard module:

    var keyboard = quill.getModule('keyboard');
    delete keyboard.hotkeys[13];
    

    A removeHotkey API has been added on the keyboard module but this is not released an any official version yet.