Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any chance to trigger the validation process manually? #126

Open
simonwidjaja opened this issue Dec 30, 2014 · 7 comments
Open

Any chance to trigger the validation process manually? #126

simonwidjaja opened this issue Dec 30, 2014 · 7 comments

Comments

@simonwidjaja
Copy link

BTW: Thanks for the great work!

@simonwidjaja
Copy link
Author

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!

@rickharrison
Copy link
Owner

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.

@tristanjahier
Copy link

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

@benbrowning
Copy link
Contributor

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

@leggleton
Copy link

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.

@dancinglone
Copy link

i really want a manual trigger too!!!

@dancinglone
Copy link

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

BinaryGeometry pushed a commit to BinaryGeometry/validate.js-1 that referenced this issue Jan 29, 2018
This commit resolves issue rickharrison#197 might be helpful as a starting point for issue rickharrison#126

Adds a public valididateOne method to the validateForm object which allows you to validate a single field manually.

/* Usage */  
var valid, field; field = $('[name="name"]).attr('name"); valid = validator.validateOne(field)
if(!valid === true){ 	/* valid === [{name, "name", message="Current error" messages="[Current error, Other errors]"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants