Disable Form Submission via Enter Key

Disable Form Submission via Enter Key

sitesurfersitesurfer Posts: 34Questions: 9Answers: 0
edited June 2014 in Editor

Afternoon all.

A real quicky after an hour of stumbling around :)

I have attempted to disable the default behaviour of the Enter key submitting the Editor form by a couple of methods:

1) Via the preSubmit event (this simply stops validation too so no use)
2) Via a delegated on keypress event against the form - this however doesnt stop the form submitting.

I have used the event to provide a .preventDefault on the form - which I suspect may not be the way to go.
I;d add that I am using the on event which allows for future creation of the modal (and is tested to establish that the keypress is picked up).

Is there a blindingly obvious way that I have missed?

$("body").on("keydown",$("form.form-horizontal"), function (e) {
    if (e.keyCode == 13) {
        e.preventDefault();
        console.log(e);
        return false;
    }
});

Oo

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    The submitOnReturn option of the form-options object can be used to disable Editor's submit on return behaviour. Full details.

    Allan

  • sitesurfersitesurfer Posts: 34Questions: 9Answers: 0
    edited June 2014

    Hi Allan

    Thanks for that:

    I have this:

    $("body").on("keydown",$("form.form-horizontal"), function (e) {
    
        if (e.keyCode == 13) {
    
             editor.edit(this, {
                    submitOnReturn: false
                })
        }
    });
    

    Which now triggers an impressive javascript error, to quantify my thinking here - because i don't have a form id, I'm capturing future enter key presses and then telling editor to ignore them, would that be the thinking or have I got it all about face?

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Are you using the TableTools buttons for Editor rather than calling edit() yourself? If so use the formOptions.main option and set submitOnReturn to false there.

    Allan

  • sitesurfersitesurfer Posts: 34Questions: 9Answers: 0

    Hi Allan

    I found out what I was doing wrong. Taking your advice I dropped the 'submitOnReturn' option into the editor setup and then went and tweaked the javascript to remove the 'friendly' text field.

    Works A1 now thank you!

This discussion has been closed.