Open risanto opened 3 years ago
const Validator = require('validatorjs')
const data = {
name: 'John',
hasAllergy: true
};
const rules = {
name: 'required',
hasAllergy: 'required|boolean',
allergicTo: 'required_if:hasAllergy,true'
}
const validation = new Validator(data, rules)
console.log('validation result', validation.passes()) // expected `false` but shows `true`
@risanto did you find the solution?
As shown in this closed issue #252. You can solve it using the array/object notation. Here is a working example:
const Validator = require('validatorjs');
const data = {
name: 'John',
hasAllergy: true,
};
const rules = {
name: ['required'],
hasAllergy: ['required', 'boolean'],
allergicTo: [{ required_if: ['hasAllergy', true] }],
};
const validation = new Validator(data, rules);
console.log('validation result', validation.passes()); // expected `false` and shows `false`
So, I set up these rules:
And it's supposed to check for url when the channel is 1, but the problem is when I send this payload it passes just fine and doesn't trigger required or the subsequent url_validation (a custom validation).