In some extent, You CAN trigger
HTML5 form validation and show hints to user without submitting the form!
Two button, one for validate, one for submit
Set a onclick
listener on the validate button to set a global flag(say justValidate
) to indicate this click is intended to check the validation of the form.
And set a onclick
listener on the submit button to set the justValidate
flag to false.
Then in the onsubmit
handler of the form, you check the flag justValidate
to decide the returning value and invoke the preventDefault()
to stop the form to submit. As you know, the HTML5 form validation(and the GUI hint to user) is preformed before the onsubmit
event, and even if the form is VALID you can stop the form submit by returning false or invoke preventDefault()
.
And, in HTML5 you have a method to check the form's validation: the form.checkValidity()
, then in you can know if the form is validate or not in your code.
OK, here is the demo: http://jsbin.com/buvuku/2/edit