vee-validate icon indicating copy to clipboard operation
vee-validate copied to clipboard

V4 required_if rule missing?

Open AntonioDell opened this issue 2 years ago • 5 comments

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

AntonioDell avatar Jan 12 '23 08:01 AntonioDell

I also need to know how to do if_unless, but it seems it doesnt do a validation on the last keystroke 🤔

9mm avatar Jan 14 '23 13:01 9mm

Dropped them during the upgrade to v4 and never implemented them since, will consider adding them in the next minor release.

logaretm avatar Jan 14 '23 15:01 logaretm

Any news on this?

alexey-v-paramonov avatar Nov 02 '23 10:11 alexey-v-paramonov

Did anyone made a custom implementation of a required_if in the v4 please ?

guyaumetremblay avatar Jan 11 '24 16:01 guyaumetremblay

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.

guyaumetremblay avatar Jan 11 '24 18:01 guyaumetremblay