Stop validation process if a rule return false, in checkAsync
I do not know if this is doable currently. I could not find any doc for this. I want the validator to stop immediately when a rule for an attribute fails. It seems the validator continues to execute all the rules for that attribute. This is happening only when using checkAsync.
Example:
const Validator = require('validatorjs');
Validator.registerAsync(
'unique',
(value, attribute, req, passes) => {
console.log('unique called');
// Pseudo code
setTimeout(() => {
passes(false, 'The username already exists');
}, 500);
},
'The :attribute does not exist'
);
let validator = new Validator({username: 1234}, { username: 'required|string|unique' });
validator.checkAsync(
() => {
console.log('passes');
},
() => {
console.log('fails');
}
);
In above code, the unique rule should not be executed (at least, in my use case). But all the rules are being executed and unique called is printed on console.
How can I stop immediately when a rule fails?
Any update on this?
I have not had a chance to review this deeper, but for clarification sake, I am understanding you want this validation to fail at the string rule and stop all remaining validation for the attribute under test, this never hitting unique , but all remaining futS will continue