validate.js icon indicating copy to clipboard operation
validate.js copied to clipboard

Any chance to trigger the validation process manually?

Open simonwidjaja opened this issue 11 years ago • 7 comments

BTW: Thanks for the great work!

simonwidjaja avatar Dec 30 '14 13:12 simonwidjaja

I took a closer look at the code and found the "private" function "_validateForm".

I'm using the following jQuery snippet after the first submit attempt. So when the user goes back to the invalid field and changes the value to a valid one he/she gets validation feedback right away and doesn't have to hit submit again to see the result...

$("input[name^='poll_']").change(function() { validator._validateForm(null); });

Do you have any concerns with this approach? I guess there is a reason why this function is pseudo private.

Thanks again!

simonwidjaja avatar Dec 30 '14 13:12 simonwidjaja

I just haven't had time to expose a proper public API to fit this use case. Using _validateForm is fine with the current version, but I would always check when you are upgrading to make sure everything still works as is.

I'm pretty swamped right now so I'd be very open to a PR with a better API for this use case.

rickharrison avatar Dec 31 '14 20:12 rickharrison

I also think that a manual trigger function is a very good idea. ;-)

tristanjahier avatar Jan 12 '15 16:01 tristanjahier

Me too. Having a public call to validate the whole form and another to validate just one given field would be super useful.

benbrowning avatar Jan 13 '15 11:01 benbrowning

I was able to alter validate.js to call it manually as I wanted to integrate field validation with other validation types such as validation that involves more than one field. I did this by creating a wrapper around the call to the validation object. The wrapper is bound to an onclick event. I also had to remove a few lines in validate.js. I removed var _onsubmit = this.form.onsubmit and altered the code below that as well so that the lines below were just an anonymous function that called _validateForm(evt) upon creation of the ValidateForm object.

leggleton avatar Mar 22 '15 12:03 leggleton

i really want a manual trigger too!!!

dancinglone avatar Jul 06 '15 08:07 dancinglone

what's more , i don't want one with jq

dancinglone avatar Jul 06 '15 08:07 dancinglone