Remove form validation rule on click event of Specific Button
Remove form validation rule on click event of
Specific Button
Apply or Remove rules on the Button when click event occurs.
$('#btnSubmit’).on('click', function(){
$('[name="Postcode"]').rules ('add', {
required: true,
email: true
});
$('#County).rules('remove');
$('#personal-details-form'). valid (); // Trigger the validation & do
NOT submit
});
And also, when you use other button,
while using Click event, remove rules applied on
#btnSubmit’ click.
Just in your case if you want to
Invalidate Surname if you have
set using other buttons, use
$('[name="Surname"]').rules('remove');
$('[name="FirstName"]').rules('remove');
Example:
$(document).ready(function () {
$('#myform').validate({ // initialize the plugin on your form
// options,
rules and/or callbacks
});
// IMPORTANT:
buttons are NOT type="submit"
$('#button1').on('click', function(){ // capture the click
$('#myfield').rules('add', { // dynamically declare the rules
required: true,
email: true
});
$('#myOtherField').rules('remove'); // remove the other rules.
//
another '.rules()' call, etc.
$('#myform').valid(); // trigger the validation & do NOT submit
});
$('#button2').on('click', function(){ // capture the click
$('#myOtherField').rules('add', { // dynamically declare the rules
required: true,
digits: true
});
$('#myfield').rules('remove'); // remove the other rules.
// another
'.rules()' call, etc.
$('#myform').submit(); // trigger the validation & submit
});
});
Working DEMO: http://jsfiddle.net/Kt93M/
Comments
Post a Comment