guettli
guettli

Reputation: 27806

CKEditor 'save' is different than submit

I use this, to submit the form if you hit ctrl+enter:

$(function() {
    CKEDITOR.on('instanceReady', function(evt) {
        evt.editor.setKeystroke(CKEDITOR.CTRL + 13, 'save');
    })
})

Unfortunately this seems to be a bit different to pressing the submit button.

If I hit ctrl+enter I get a popup with a warning that there is changed data in the form, and that this data would get lost. If I choose "leave the page", then everything works fine (not data gets lost).

How can I make ctrl+enter work like pressing the submit button?

Upvotes: 0

Views: 234

Answers (2)

Wizard
Wizard

Reputation: 3151

It appears that the onbeforeunload event is triggered when you save the form.

Try this to override the save event and remove the event handler:

for (var i in CKEDITOR.instances) {
    CKEDITOR.instances[i].on('save', function(evt) {
        window.onbeforeunload = null;

        // if the above line doesn't work,
        // replace it with the next line removing the two slashes
        // $(window).off('beforeunload');
    });
}

Upvotes: 2

Jakob
Jakob

Reputation: 81

Did you try replacing "save" with "submit".

CKEditor has a cache which saves the things you've typed so when you loose connection, etc. your content won't be gone.

Upvotes: 0

Related Questions