Skip to content

Fix validation error with zero values in angular range validator #356

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

Conversation

donalfenwick
Copy link
Contributor

Found an issue while using the range validator decorator in our angular application.

Take the scenario where we are trying to validate that a percentage is between 0 and 100 as in the example model below.
If the value is set as 0 in onInit after FormBuilder.formGroup() is called causes a validation error.

Added a test to demonstrate the issue and added a fix in the range validator function to accept zero as a valid value.

export class ExampleClass {
    @range({ minimumNumber: 0, maximumNumber: 100, message: 'must be in 0 to 100 range' })
    @numeric({ allowDecimal: true })
    percentageExample: number;
}

…ge is between 0-N and the initial value is set up with 0
…alidator. This avoids control.value returning false in the if statement when its value us zero.
@ajayojha ajayojha merged commit 43ee755 into rxweb:master Jul 7, 2020
@ajayojha
Copy link
Member

ajayojha commented Jul 7, 2020

@donalfenwick Thanks for this pull request :).

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

Successfully merging this pull request may close these issues.

2 participants