-
Notifications
You must be signed in to change notification settings - Fork 78
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
Async rule #98
base: master
Are you sure you want to change the base?
Async rule #98
Conversation
@ej2015 coming in hot with another PR! Awesome! My big issue with this approach is is changes fundamentally how SRV works, which I am not against but if we can do it without changing the API I think that would be even better. I started a branch a while back, then abandoned it because life happens, here is what I got to: master...async-validators It doesn't really work so take it with a grain of salt. But the main idea is that you can define validators as async which then put them into a separate bucket of validators. The regular validators will always run like normal, and only once someone tries to submit will it call each of the async validators. This separation is important to keep the fast responses of the regular validators and keep the long async validators to only happen manually and less often. I thought the sync validators would sort of work like a middleware where once one completes it calls the next one, if one fails it will stop the chain and throw an error, else it will get through them all and complete. The only api changes would be that is adds the ability to add an async rule and it adds a new pass and fail callback setup which looks something like this: submitForm() {
this.setState({processing: true});
this.validator.asyncValid({
pass: () => {
alert('You submitted the form and stuff!');
this.setState({processing: false});
},
fail: () => {
this.validator.showMessages();
this.setState({processing: false});
}
});
} This still leaves the normal way of calling Again this does not work but it is a little bit more along the lines of where I was hoping to move with this. Open to discussion. |
Was looking at your branch. Can you explain more what the async validator is supposed to look like? And why did you say it's not working? |
My attempt at bringing in async validation rules(#40). Main ideas:
message
method into two new methods:validate
does the validation,message
does the renderingUsage Example: