I have a form with multiple fields that I\'m validating (some with methods added for custom validation) with Jörn Zaeffere\'s excellent jQuery Validation plugin. How do you
You can use the onsubmit:false option (see documentation) when wiring up validation which will not validate on submission of the form. And then in your asp:button add an OnClientClick= $('#aspnetForm').valid(); to explicitly check if form is valid.
You could call this the opt-in model, instead of the opt-out described above.
Note, I am also using jquery validation with ASP.NET WebForms. There are some issues to navigate but once you get through them, the user experience is very good.
I have two button for form submission, button named save and exit bypasses the validation :
$('.save_exist').on('click', function (event) {
$('#MyformID').removeData('validator');
$('.form-control').removeClass('error');
$('.form-control').removeClass('required');
$("#loanApplication").validate().cancelSubmit = true;
$('#loanApplication').submit();
event.preventDefault();
});
Here is the simplest version, hope it helps someone,
$('#cancel-button').click(function() {
var $form = $(this).closest('form');
$form.find('*[data-validation]').attr('data-validation', null);
$form.get(0).submit();
});
Other (undocumented) way to do it, is to call:
$("form").validate().cancelSubmit = true;
on the click event of the button (for example).
You can add a CSS class of cancel
to a submit button to suppress the validation
e.g
<input class="cancel" type="submit" value="Save" />
See the jQuery Validator documentation of this feature here: Skipping validation on submit
EDIT:
The above technique has been deprecated and replaced with the formnovalidate
attribute.
<input formnovalidate="formnovalidate" type="submit" value="Save" />
Yet another (dynamic) way:
$("form").validate().settings.ignore = "*";
And to re-enable it, we just set back the default value:
$("form").validate().settings.ignore = ":hidden";
Source: https://github.com/jzaefferer/jquery-validation/issues/725#issuecomment-17601443