Reputation: 964
So I have this form and I really want to use html5 validation. Problem is, there are two things my form needs to do:
Simply save the current state so it can be reloaded later (via jsp/servlets) (WITHOUT VALIDATING)
Actually submit the form (validate it before submitting)
Is there a way to turn off validation for a given button/submit but keep it for the other?
My workaround would be to use an AJAX call for the former and regular submit for the latter, but it kind of messes up the system I have in place.
Upvotes: 8
Views: 2829
Reputation: 9432
You can add the "novalidate" attribute when the user clicks on a given button.
<form method="post" action="/foo" novalidate>...</form>
This disables html validation. Add it again when you want your final submission.
EDIT
Apparently there's a better option, the formnovalidate attribute, that you can add to a specific field (which apparently is exactly what you want):
<form action="demo_form.asp">
E-mail: <input type="email" name="userid"><br>
<input type="submit" value="Submit"><br>
<input type="submit" formnovalidate="formnovalidate" value="Submit without validation">
</form>
Upvotes: 12
Reputation: 2156
Yes, by toggling the novalidate
attribute (or the noValidate
property on the HTMLFormElement
object) with JavaScript.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-novalidate
Upvotes: 1