vee-validate
vee-validate copied to clipboard
V4 required_if rule missing?
What happened?
In V3 there was the required_if rule as built-in rule available. After some searching I cannot seem to find it in V4 packages. Also no mention of it's removal as far as I could find.
Was this rule removed on purpose? If yes: What was the reasoning behind it and is there an alternative (maybe chaining multiple rules) to it or do I need to re-create it myself?
Reproduction steps
Compare rules between V3 and V4. In V3 the required_if rule exists, in V4 not.
Version
Vue.js 3.x and vee-validate 4.x
What browsers are you seeing the problem on?
- [X] Firefox
- [X] Chrome
- [X] Safari
- [X] Microsoft Edge
Relevant log output
No response
Demo link
No Link necessary I think.
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
I also need to know how to do if_unless, but it seems it doesnt do a validation on the last keystroke 🤔
Dropped them during the upgrade to v4 and never implemented them since, will consider adding them in the next minor release.
Any news on this?
Did anyone made a custom implementation of a required_if in the v4 please ?
If it can help somebody, I did this :
defineRule("required_if", (value, [target, targetValue]: [string, any], ctx) => {
if (targetValue === ctx.form[target]) {
return required(value);
}
return true;
});
It works well in object notation like this:
{ required_if: ['enabled', true] },
In string notation, the targetValue seems to always been a string so the comparison will failed.