I have a form on my jQuery Mobile site that I would like to validate, and stop submission if validation does not pass.
However, 'return false' does not stop the form from being submitted, because jQuery Mobile is submitting the form via Ajax. How can I stop the form submission?
$("#form").live('submit', function(){
alert('test');
return false;
});
The above code fires the alert, but does not stop the form from being submitted. If I use data-ajax="false" on the form tag it works correctly, but I would rather use the Ajax submission if possible.
Use data-ajax="false"
and bind your own ajax form submission code that only runs if validation passes:
$("#form").live('submit', function()
{
if (formValidates)
{
$.post(...);
}
return false;
});
I agree with bmaland and had the same problem. Here is what worked well for me:
$(document).on("pagecreate","#Home",function(){
$("#myFormSearch").submit(function(){
myRealSubmit();
return false;
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With