-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Verify - dependent rules #1628
Comments
Since the Until I can come up with a good way to use it I'm afraid it will be left out, also drafting this API is critical for #1625 to support these types of rules. I was thinking about something like this: validator.verify(value, rule, {
// validation options?
deps: {
confirmed: 'otherValue',
after: 'afterValue'
}
}); A little verbose yes, but very flexible and will hardly change in the future. What do you think? |
Hey Abdel, I'm curious as to why it needs access to refs anyway; are we not just passing in data? Maybe I am using this incorrectly anyway? To test, I used a basic validator: import VeeValidate from 'vee-validate'
const Validator = VeeValidate.Validator
const rules = {
password1: 'required|alpha|confirmed:password2',
password2: 'required|alpha|confirmed:password1',
}
const values = {
password1: 'hello',
password2: 'hello'
}
const validator = new Validator(rules, {})
validator
.validateAll(values)
.then(result => {
console.log(result ? 'pass' : 'fail')
console.log(validator.errors)
})
Should this not validate? |
Regarding your thoughts on /**
* Verify a value
*
* @param {string} value The value to validate
* @param {string} rule The rule to process the value with
* @param {object} options A hash of options that the validator may need to cross-check values
*/
function verify (value, rule, options) {
// verify
}
const rules = {
username: 'required|alpha|min:5',
password1: 'required:password|matches:password2',
password2: 'required:password|matches:password1'
}
const values = {
username: 'dave',
password1: 'letmein',
password2: 'letmeinn'
}
const options = {
values, // other form values, to look up if needed
field: 'password1' // name of validated field, needed to (optionally) replace {field} in returned error message
}
verify(values.password1, rules.password1, options) |
What I meant by the ref argument, that while the rules conveniently only care about the passed values rather than how they are they resolved. The implementation only has one way of dealing with those fields i.e: fetching them using refs. Cross-checking values with programatic API wasn't implemented. Your second argument while is expected of I like the API proposed by you here, I might implement it like you suggested. |
Well, either way! Let me know how you go. I released Vee Element this morning: If we can get dependent rules validating here, I will be a happy man! Unless you have any better suggestions, like implementing a new Validator instance? |
Congrats on the plugin release 🎉 Will be sure to mention it in the docs and here in the README. Currently my work on #1625 has opened my eyes to simpler approach to how validation should be done. Functional approach to fields should reduce the footprint of vee-validate in the future, I'm planning a re-write once I'm done with the Army service in few months, the re-write have a few goals:
This might warrant a major release |
Ahhh, I wondered what Army meant in your Twitter bio! Are you using TS yet? We are at work now, and it's pretty great! But also infuriating at times - though normally because you don't know it well enough. Though we suspect sometimes because there's still improvements to be made 😝 . Yeah, nothing wrong with a 3.0 release if you have to. So not really sure where to leave this thread... close it? Sounds like the current API has its limitations. Will you release a minor update with |
The options will be released with the next release around this week since it doesn't break anything. I'm still learning TS at the moment, once I'm comfortable with it I will decide whether I would it use it or not. |
Woohoo!
Feel free to hit me up on Twitter / email - if I can help, I will |
The docs state that
validator.verify()
cannot use dependent rules withoutv-validate
:However, I don't understand why this is so.
Surely as an independent function, the additional values / rules could be passed in?
In my case, I will have all these, so it should be simple to derive a response?
The text was updated successfully, but these errors were encountered: