-
Notifications
You must be signed in to change notification settings - Fork 44
Async custom validations #42
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
Comments
Hi there... I'm not sure I understand what this means. Can you say more? |
Hi Chris var validate = new Bouncer('form', {
customValidations: {
isHello: async function (field) {
const response = await fetch('/remote', {
method: 'POST',
body: JSON.stringify({
value: field.value
}),
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
}});
const validation = await response.json();
return !validation.valid;
}
}
}); |
Sorry, I meant: what is it you're trying to accomplish? It looks like perhaps using a server to validate values instead of the client? |
Let's say we want to check whether a username is already taken. It saves the user an enormous amount of time getting informed while typing that another name needs to be chosen instead of having to submit the form to the server first. |
Ah yea, I can see that. My preference would be to not make async a default behavior, as this is really intended to augment native form validation. I wonder how else I can support that kind of behavior, though. Let me give that a bit of thought. |
Ah, very good point. Would some kind of plugin approach be an option, allowing users to overwrite The changes I made for my requirement to work: master...backflip:master |
Did anything come of this request? I need to compare a form value to a set of metadata that has to be fetched from a server. |
It would be great to have async custom validations, e.g. for doing remote validation. Would you consider a PR changing the API to being async by default? Or would you recommend another approach?
The text was updated successfully, but these errors were encountered: