Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop validation process if a rule return false, in checkAsync #425

Open
iarkaroy opened this issue May 2, 2021 · 2 comments
Open

Stop validation process if a rule return false, in checkAsync #425

iarkaroy opened this issue May 2, 2021 · 2 comments
Assignees

Comments

@iarkaroy
Copy link

iarkaroy commented May 2, 2021

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?

@mikeerickson mikeerickson self-assigned this May 4, 2021
@iarkaroy
Copy link
Author

iarkaroy commented Jun 7, 2021

Any update on this?

@mikeerickson
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants