fonk-required-by-field-validator
- Validate if a field of a form is required by another field.
state: [
{
validator: requiredByField.validator,
customArgs: {
field: 'country',
value: 'U.S.A',
},
},
],
},
};
```
- Or with a
condition
:
state: [
{
validator: requiredByField.validator,
customArgs: {
field: 'country',
condition: fieldValue =>
fieldValue === 'U.S.A' || fieldValue === 'Australia',
},
},
],
},
};
```
- Another
condition
:
state: [
{
validator: requiredByField.validator,
customArgs: {
field: 'country',
condition: (fieldValue, values) =>
fieldValue === 'U.S.A' && values.person === 'John',
},
},
],
},
};
```
You can customize the error message displayed in two ways:
- Globally, replace the default error message in all validationSchemas (e.g. porting to spanish):
- Locally just override the error message for this validationSchema:
state: [
{
validator: requiredByField.validator,
customArgs: {
field: 'country',
value: 'U.S.A',
},
message: 'Required field',
},
],
},
};
```
Please, refer to fonk to know more.
License
MITAbout Basefactor + Lemoncode
We are an innovating team of Javascript experts, passionate about turning your ideas into robust products.
Basefactor, consultancy by Lemoncode provides consultancy and coaching services.
Lemoncode provides training services.
For the LATAM/Spanish audience we are running an Online Front End Master degree, more info: http://lemoncode.net/master-frontend