Conditional built-in validators
See original GitHub issueHi there, I’m looking for a super basic conditional validation using built-in validators, but can’t seem to figure out how to accomplish it with vuelidate.
In essence:
fixedFee: {
required: requiredIf('hasFixedFee'),
minValue: minValue(1),
},
Problem is that minValue
validator always triggers, even if fixedFee
is empty or not required. How can I use the built-in minValue
validator but make it conditional to hasFixedFee
like requiredIf
?
Having to supply my own validation function for such a simple use case seems overly complicated to me.
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (7 by maintainers)
Top Results From Across the Web
Conditional Validation in Reactive Forms - Codementor
Validating your application form before reaching out to the server enhances security and performance.
Read more >Conditional Vuelidate Validator - Stack Overflow
i want to have a conditional validator that checks for (in this case) minValue(0) or minValue(0.01), depending on other things on the page....
Read more >Angular Conditional Validation - ConcretePage.com
To perform conditional validations with formControlName , formControl and ngModel using built-in validators, we can use build-in validator ...
Read more >Reactive Forms Benefits: Conditional Validation - Preston Lamb
If the value is false , we clear all the validators. But the last part is very important as well.
Read more >Active Record Validations - Ruby on Rails Guides
5 Conditional Validation ... Sometimes it will make sense to validate an object only when a given predicate is satisfied. You can do...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You could create such a helper.
Here is an example - https://jsfiddle.net/dobromir/d20bL4oj/10/
Helper
Usage
If anyone finds this useful, please vote or something, I could add it as a helper 😃
I have solved a similar problem using dynamic validation schema, and it seems to me this is closely related. The docs are here: https://vuelidate.js.org/#sub-dynamic-validation-schema
My problem was having to validate a different set of fields based on selection. Ie, based on paymentType selection validate the appropriate input fields:
Applied to the OP’s problem it would look like: