Require only one of 4 fields
See original GitHub issuevalidationSchema={
Yup.object().shape({
emailAddress: Yup.string().email('Please enter a valid email address'),
phoneHome: Yup.number().typeError('Home Phone must be a number'),
phoneMobile: Yup.number().typeError('Mobile Phone must be a number'),
phoneWork: Yup.number().typeError('Work Phone must be a number'),
})
.test(
'at-least-one-contact',
'You must provide at least one contact method',
value => {
const test = !!(value.emailAddress || value.phoneHome || value.phoneMobile || value.phoneWork);
return Yup.ValidationError(['emailAddress', 'phoneHome', 'phoneMobile', 'phoneWork'], 'one is required', '');
}
)
}
Basically I am getting an error on the value => {
definition saying
Type 'ValidationError' is not assignable to type 'boolean | Promise<boolean>'.
Is there an easy way to do this so only one field is required?
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
at least one field is required in angular 4 forms - Stack Overflow
I'm using angular 4 forms and I ...
Read more >Requiring at least one field - FormValidation
Requiring at least one field. In fact, the form might have multiple fields with the same validator rules but at least one of...
Read more >Restrict data input by using validation rules - Microsoft Support
You can compare values across different fields using a record validation rule. For example, a record with two date fields might require that...
Read more >TypeScript: Modeling Required Fields with Mapped Types
This is just a another little TypeScript tip I'll spend too long explaining. ... For example there is Partial that makes all fields...
Read more >Queries and Mutations - GraphQL
Try adding an appearsIn field to the hero object in the query, and see the new result. In the previous example, we just...
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 FreeTop 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
Top GitHub Comments
I use this:
@calmattack,
I had a similar situation and solved it with the following code.
My solution requires selecting other input elements and checking the value. With more time you could probable adept @risenforces solution to pass in the schema for validation instead of selecting elements.