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: