javascript - jQuery Validate stop form submit -
i using jquery validate form, when form validated reloads or submits page want stop action. use event.preventdefault(), doesn't work.
here code:
$("#step1form").validate(); $("#step1form").on("submit", function(e){ var isvalid = $("#step1form").valid(); if(isvalid){ e.preventdefault(); // things after validation $(".first_step_form").fadeout(); if(counter == 3){ $(".second_step_summary").fadein(); $(".third_step_form").fadein(); $(".third_inactive").fadeout(); }else if(counter < 3){ $(".second_step_form").fadein(); $(".third_inactive").fadein(); } $(".first_step_summary").fadein(); $(".second_inactive").fadeout(); } return false; });
the submithandler
callback function built plugin.
submithandler
(default: native form submit):callback handling actual submit when form valid. gets form argument. replaces default submit. right place submit form via ajax after validated.
since submithandler
automatically captures click of submit button , fires on valid form, not need submit handler, nor need use valid()
test form.
you code can replaced with:
$("#step1form").validate({ submithandler: function(form) { // things after validation $(".first_step_form").fadeout(); if(counter == 3){ $(".second_step_summary").fadein(); $(".third_step_form").fadein(); $(".third_inactive").fadeout(); }else if(counter < 3){ $(".second_step_form").fadein(); $(".third_inactive").fadein(); } $(".first_step_summary").fadein(); $(".second_inactive").fadeout(); return false; // block default submit action } });
Comments
Post a Comment