I have one form with around 50 fields and two submit buttons, "SAVE" and "SAVE & SUBMIT". If the user clicks "SAVE", then validate only some values, eg. field1, field2. When user clicks "SAVE & SUBMIT" button, it should validate all 50 fields and submit.
<form id="myform">
<input type="text" name="field1" />
<br/>
<input type="text" name="field2" />
<br/>
<input type="text" name="field3" />
<br/>
<input type="text" name="field4" />
<br/>
<input type="submit" id="button1" value="Save" />
<input type="submit" id="button2" value="Submit" />
</form>
$(document).ready(function () {
$('#button1').click(function(){
$("#myform").validate({
rules: {
field1: {
required: true
},
field2: {
required: true
}
},
submitHandler: function (form) { // for demo
alert("data saved");
}
});
});
$('#button2').click(function(){
$("#myform").validate({
rules: {
field1: {
required: true
},
field2: {
required: true
},
field3: {
required: true
},
field4: {
required: true
}
},
submitHandler: function (form) { // for demo
alert("data submited");
}
});
});
});
I have created jsfiddle for this: example test
validateis designed to be applied once to a form. Whichever button you press first is setting the validation from then onwards. You would need to figure out how to strip existing validation from all fields before applyingvalidateagain.validateare you using (download page please)? Some validation plugins allow you to add and remove rules dynamically (but I have a feeling yours is not one of those)..validate()code, and the jquery-validate tag. And yes, it allows dynamic rule changes.