I have two buttons, one for Next and one for SAVE when clicking Next I would like to let jQuery do its validation, but when SAVE is CLICKED jQuery will not do its validation. Are there event handlers for this?
3 Answers
The jQuery Validation plugin will automatically capture/validate on any button or input (within the <form></form> container) with type="submit" and ignore any with type="button".
<button type="submit">NEXT</button>
<button type="button">SAVE</button>
OR
<input type="submit" value="NEXT" />
<input type="button" value="SAVE" />
Alternatively, adding a class="cancel" to the button will cause the plugin to ignore it.
<button type="submit">NEXT</button>
<button type="submit" class="cancel">SAVE</button>
OR
<input type="submit" value="NEXT" />
<input type="submit" class="cancel" value="SAVE" />
1 Comment
OldTrain
Thanks for the tip, it's found in the jquery.validate.js
// allow suppresing validation by adding a cancel class to the submit button this.find("input, button").filter(".cancel").click(function() { validator.cancelSubmit = true; });