Prevent form submission on login with Meteor

When I click on a field inside the form and press Enter, the form is submitted.

This is not good for my use and should be avoided.

I went through several steps without success:

template.rendered

$('#myForm').on("keyup keypress", function(e) {
    var code = e.keyCode || e.which;
    if (code  == 13) {
        e.preventDefault();
        return false;
    }
});

$("form").submit(function( event ) {
    event.preventDefault();
});

      

Template.events

"keyup #myform": function(event){
  event.preventDefault();
}

      

Nothing has helped yet. I am using Meteor and semantic-ui.

What else can help?

+3


source to share


3 answers


Change this:

"keyup #myform": function(event){
  event.preventDefault();
}

      

in



"submit #myform": function(event){
  event.preventDefault();
}

      

Pressing "enter" triggers "submit", you're wasting time trying to figure out which keycode is associated with "enter".

+5


source


Shouldn't you use an event keydown

if you want to prevent the form from being submitted only when the user presses "enter" on the form field?



This way you can even only allow it for the last field of your form.

0


source


Try the following:

Template.<your_template_name>.events({        
   // Submit form event
    'submit form': function(event){
        // Stop form submission
        event.preventDefault();
    }
});

      

0


source







All Articles