Validator equalTo, equalNotTo, equalToWhen rules #1475
Replies: 2 comments 7 replies
-
Hey! 👋 What's the goal of having |
Beta Was this translation helpful? Give feedback.
-
I was thinking about this proposal and I think, all we need is just the
In your rules.equalToWhen('USD', 'country', '=', 'United states')
rules.equalToWhen('INR', 'country', '=', 'India')
rules.equalToWhen('EUR', 'country', 'in', ['Germany', 'France', 'and so on']) As you notice, you are running redundant validations (one for each country). Whereas, in the perfect world, we first want to know the user country and then enforce a currency. Something as follows: const userCountry = this.ctx.request.input('country')
const currencies = {
'United states': 'USD',
'INR': 'India'
}
rules.equalTo(currencies[userCountry]) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I think that the validator misses some trivial rules, like equalTo, equalNotTo, equalToWhen,
equalTo and equalNotTo are straightforward, field matches a value provided.
equalToWhen can act a bit like requiredWhen, if other field matches a condition, value should be equal to.
I wrote a bit of code for equalToWhen, inspired by requiredWhen, haven't tested it yet to see if it works but could work on it a bit more if @thetutlage decides this feature is relevant.
Beta Was this translation helpful? Give feedback.
All reactions