Validator.min/max always passes validation on NaN/string input
See original GitHub issueWhich @angular/* package(s) are the source of the bug?
forms
Is this a regression?
No
Description
I have a text input with a Validator.min on it. If a text string is entered into the form, the validator will parse this to NaN and return null since NaN passes the less/greater than checks. This leads to the form accepting all string inputs!
I looked up this in the code:
So judging by the comment it seems to be intentional. But I think the spec has been misinterpreted. The spec says:
If the element has a min attribute, and the result of applying the algorithm to convert a string to a number to the value of the min attribute is a number, then that number is the element’s minimum; otherwise, if the type attribute’s current state defines a default minimum, then that is the minimum; otherwise, the element has no minimum.
So the spec is talking about parsing the min/max attribute, not the actual value of the input itself.
I think it would make more sense if NaN always failed the validator or am I just not seeing why this is useful…
Please provide the environment you discovered this bug in
@angular/forms@10.2.5
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (1 by maintainers)
Top GitHub Comments
@jonathanazulay We are following the standard HTML behaviour for the min/max validations. I have created a simple stackblitz example to demonstrate this. In the example you will see that I have set the
min/max
and also set thetype
totext
. According to MDN, the:invalid
pseudo class will be added for non-valid inputs and:valid
will be added when the field is valid. The example shows that the field is valid, which is exactly what our validators do as well.Based on the above findings I am closing this ticket.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.