Search code examples
aloha-editor

Preventing line breaks - ENTER keypresses. Instead - fire custom event


I'd like to use Aloha to WYSIWYG-edit single-line headlines.

For that I need to intercept ENTER keypress (to prevent line-break) and fire custom save event.

Is there a way to do that?

Thanks!


Solution

  • Here's what worked for me on "hotfix" branch:

    Aloha.bind('aloha-smart-content-changed', function(e, data) {
        value = data.editable.getContents();
        // save it to database.
    });
    Aloha.bind('aloha-command-will-execute', function(e, data) {
        if (data.commandId == 'insertlinebreak') {
            data.preventDefault = true;
        }
    });
    

    More info here:

    https://github.com/alohaeditor/Aloha-Editor/issues/1502