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

conditionalExpression for greaterThan hits twice on input change with old value #614

Open
vytautas-pranskunas- opened this issue Dec 9, 2022 · 0 comments

Comments

@vytautas-pranskunas-
Copy link

Hello,

I am trying to implement greaterThan comparing two custom values and what i have noticed that validator is called twice: first time with latest value, second time with old value (and since old value is latest it leads to wrong validation)

my code:

static greaterThan = (fieldName: string, message = 'validators.greaterThenMsg') =>
        RxwebValidators.greaterThan({
            message,
            fieldName,
            conditionalExpression: (x: any, y: any) => {
                console.log(x);
                console.log(y);

                return false;
            },
        });

form

form: FormGroup = this.fb.group({
        timeFrom: ['', [Validator.required()]],
        timeTo: [
            '',
            [
                Validator.required(),
                Validator.customGreaterThan('timeFrom'),
            ],
        ],
    });

values received:
Screenshot 2022-12-09 at 12 27 49

as you can see first call to validator (on value change) is with correct value and the second with previous one.

I have implemented custom Angular style validator and everything is going fine (so this is not an issue with change detection runing multiple times o not an issue with value bying set to old one somehow)

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

No branches or pull requests

1 participant