question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validator.min/max always passes validation on NaN/string input

See original GitHub issue

Which @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:

https://github.com/angular/angular/blob/1d9d02696eadbee2c2f719e432efca22f1e494e9/packages/forms/src/validators.ts#L416-L426

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:closed
  • Created 2 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
sonukapoorcommented, Oct 12, 2021

@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 the type to text. 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.

0reactions
angular-automatic-lock-bot[bot]commented, Nov 12, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Min / Max Validator in Angular 2 Final - Stack Overflow
To apply min/max validation on a number you will need to create a Custom Validator. Validators class currently only have a few validators,...
Read more >
Regression introduced by new min max validators #42267
Specifically verify (by adding tests) that there is a way to conditionally disable validation, update input types accordingly (to allow for null ...
Read more >
Validators — WTForms Documentation (2.3.x)
A validator simply takes an input, verifies it fulfills some criterion, such as a maximum length for a string and returns. Or, if...
Read more >
Standards and Guidelines for Validating Next-Generation ...
An understanding of the process required to validate fully a set of pipelines in which the full algorithmic details are unknown is critical...
Read more >
FOOTER.txt - UCSC Genome Browser Downloads
The input bedGraph file must be sorted, use the unix sort command: sort ... -chromInfo=file.txt Specify chromInfo file to validate chrom names and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found