-
Notifications
You must be signed in to change notification settings - Fork 2
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
allow for custom validators/sanitizers #7
Comments
I see three possible APIs for this:
name: {
isLength: {
options: {
min: 6
},
errorMessage: 'Minimum length 6 characters.'
},
isUppercase: true,
pv_customValidator: function myCustomValidator(value) { ... }
}
const validators = { ... };
const validators = { ... };
const customHandlers = {
validator: { name: function myCustomValidator(value) { ... } },
sanitizer: { name: function myCustomSanitizer(result) { ... } }
};
const ContactValidator = ProxyValidator(validators, sanitizers);
name: {
isLength: {
options: {
min: 6
},
errorMessage: 'Minimum length 6 characters.'
},
isUppercase: function myCustomValidator(value) { ... }
} |
I think the 3rd options is the best. It should be straightforward to implement. |
Ok I agree. If we’re messing with the boolean/object value of the schemas. We might want to fix in the same PR an issue I just discovered. 😕 There can be validators that receive three arguments. We’re only covering the cases where there’s two. So maybe we could add support for the value inside options to be not just an object but an array too, this way we can spread it. What do you think? |
I like the idea of it being an array to support multiple arguments. There should be some more tests to cover these use cases. |
I agree, we can work together on it. We can split the work. |
I like the fact that this is just a declarative wrapper for the validator lib, but what if we have some custom logic we would like to apply to a field?
How should this be done? I will be happy to submit a PR based on your suggestion.
The text was updated successfully, but these errors were encountered: