jquery - jqueryvalidate $.post using submitHandler -
i'm building small app using jquery mobile , using jqueryvalidate http://jqueryvalidation.org/ form validation. managed post working using ajax moved submithandler: function(form) still "works" have click submit twice work? please i'm baffled!
//the validation stuff $().ready(function() { // validate new id form $("#addid").validate({ errorplacement: function(error, element) { error.insertafter(element.parent()); // <- make sure error message appears after parent element (after textbox!) }, rules: { iddesc: "required", }, messages: { iddesc: "please enter valid description", }, submithandler: function(form) { $('#submit').click(function() { $('#addcustid').popup('close'); $.post("customer_addnewcustomerid.php", $("#addid").serialize(), function(response) { loadcustomeridentificationtype(); }); }); } }); //end validate }); // end function
thanks :)
this totally wrong...
submithandler: function(form) { $('#submit').click(function() { // <-- causing double-click situation .... $.post(....); }); }
as per documentation submithandler
callback function,
"callback handling actual submit when form valid. gets form argument. replaces default submit. right place submit form via ajax after validated."
in other words, fires when button clicked on valid form. plugin automatically handles click
, wrapping function within click
handler pointless , counterproductive.
just this...
submithandler: function(form) { .... $.post(....); return false; // not necessary, reminds me default blocked }
you can leave out return false;
line if wish. put in (doesn't hurt anything), reminds me default action
on form not going happen.
Comments
Post a Comment