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?
Asked
Active
Viewed 8,693 times
3 Answers
7
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" />

Sparky
- 98,165
- 25
- 199
- 285
-
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; });` – OldTrain May 13 '18 at 17:33
-1
$("#nextButtonId").click(validateFunction);
$("#saveButtonId").click(saveFunction);
Something like this would work

Kyle
- 59
- 1
-1
Set up two functions next()
and save()
where you would use validate()
in next()
and skip the validation in save()
.
If you provided some code we could help you further.

d9120
- 511
- 1
- 7
- 23