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

Help with RxwebValidators.custom and RxwebValidators.customAsync #650

Open
murillotlopes opened this issue May 7, 2024 · 0 comments
Open

Comments

@murillotlopes
Copy link

Help with RxwebValidators.custom and RxwebValidators.customAsync

Hello, I need help with the RxwebValidators.custom and RxwebValidators.customAsync method in Angular

I'm doing some tests to understand how the library works.

I created my form with three attributes:

this.entidadeForm = this.formBuilder.group({ age: [0, [RxwebValidators.required({ message: 'Required field' }), RxwebValidators.minNumber({ value: 10, message: 'Minimum of 10' })]], multiple: [0], beast: [0, []] });

For my test I need the beast field to be equal to age * multiple

` this.entidadeForm.get('beast')?.addValidators(RxwebValidators.custom({
customRules: [(formGroupValue: any, parentObject: any, additionalValue: any) => {

     if ((formGroupValue.idade * formGroupValue.multiplo) === formGroupValue.besta) {
       return null;
     } else {
       return { 'custom': { isValid: false, message: 'The beast value is not valid' } };
     }
   }
   ],
   additionalValue: null

 }))`

However, when modifying the input to beast, its value is read within my condition, always a previous state.

If I enter 1, it remains at 0, which is its initial state. If I type 10, it changes to 1. If I type 100, it changes to 10. And so on.

Why does it happen? Is it a library error or am I not handling my object correctly?

I thought that in this case I should work with asynchronicity, but when changing to customAsync this.entidadeForm.get('beast')?.addAsyncValidators(RxwebValidators.customAsync(...) I get the error APP_VALIDATORS[validatorName] is not a function

Package version

@rxweb/reactive-form-validators 13.0.1

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