Given:
import { required, email, numeric } from 'validators'
let fields = ['name', 'email'];
validations: {
name: {
required
},
email: {
required,
email
}
}
Now, I wanna do the require condition for each validation objects with a condition check.
Something like:
(fields.indexOf('name') > -1) ? 'required' : '';
How can I do this to dynamically set the validation conditions?
validations: {
name: {
(fields.indexOf('name') > -1) ? 'required' : '';
},
email: {
(fields.indexOf('email') > -1) ? 'required' : '';,
(fields.indexOf('email') > -1) ? 'email' : '';
}
}
P.S: I know the above syntax is wrong. But wanted to achieve something like this.