You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
<input type="number" max="{{max}}"> does not set $error.max property #2404
When using an input of type number, with the max (or min) attribute set from the model, then the max field is not set in the error object of the input. This is due to the fact that in method "numberInputType", the value of attr.max is undefined. It is (probably) set from the model only later.
Checking the HTML, shows that the max attribute gets the correct value, set from the model.
In summary, the following does not work as expected:
input type="number" max="{{max}}"
The $error for this input field does not contain a boolean value named "max".
I think the parseFloat line should be moved inside the maxValidator function. The interp seems like it's already being done beforehand, but the validator is trying to be 'smart' and pre-compute it. I've tried it and it seems to work well (in chrome)
The documentation may indicate that it's expecting a string, but it does go against expectation as this complicates things if you want all properties to be databound and not something mid-term.
Silly thing is that the spinner still limits min/max properly according to the {{expression}}, and the browser also validates the form correctly on submission if "novalidate" isn't present.
The missing bit, really, is $error.min/max not updating.
Thanks for having a look at this!
I can see everything works fine in your Plunkr and can't get it to break, so I don't know why on my case it doesn't work. The only thing I'm realising is that, on the generated HTML for my input element, angular isn't adding the ng-valid-min and ng-valid-max classes as in your Plunkr.
For enter a number, type in 115
1a. Observe that value.$error.max goes to true meaning the # has failed MAX validation
Change the dropdown to Unlimited, this should set {{max}} to 500 where before it was 100
2a. Observe that the $error still shows a max error when the number is now in the valid range.
Type 116 in the input field
3a. observe that $error.max goes to false
So the {{max}} interpolation is not re-validating the input, but changing the input causes re-validation including the new value. This is the bug we are experiencing with 1.2.13
EDIT:
We are going to see if this solves our issue until angular natively supports this: http://jsfiddle.net/g/s5gKC/
I am currently having a related issue. In my case, when the numberInputType controller is instantiated, attr.min and/or attr.max evaluate as falsy. The solution is to replace if (attr.max) with if ('max' in attr) and if (attr.min) with if ('min' in attr)
Unfortunately my employer thus far has not approved (and looks like it won't any time soon) the CLA so someone else will have to make this PR.
PS: also needs a check for NaN since attr.max could be anything during validation now.
Activity
vorburger commentedon Jul 27, 2013
this is possibly related to issue #2144 - there clearly are some issue with cross-browser input type=number.. :(
jamie-pate commentedon Sep 16, 2013
I think the parseFloat line should be moved inside the maxValidator function. The interp seems like it's already being done beforehand, but the validator is trying to be 'smart' and pre-compute it. I've tried it and it seems to work well (in chrome)
jamie-pate commentedon Sep 16, 2013
Will require further testing and unit tests, but this fixed it for me:
https://github.com/jamie-pate/angular.js/compare/scwp
jamie-pate commentedon Dec 6, 2013
This appears to be solved in the latest angular 1.2.3
rmourato commentedon Jan 8, 2014
Problem still occurring in v1.2.7.
The documentation may indicate that it's expecting a string, but it does go against expectation as this complicates things if you want all properties to be databound and not something mid-term.
Silly thing is that the spinner still limits min/max properly according to the {{expression}}, and the browser also validates the form correctly on submission if "novalidate" isn't present.
The missing bit, really, is $error.min/max not updating.
IgorMinar commentedon Jan 9, 2014
I can't repro this with 1.2.7: http://plnkr.co/edit/4HU4jdG1ljrnoXYuegQo?p=preview
it appears to work correctly. can you please post expected vs actual result and any other instructions needed to repro the bug.
rmourato commentedon Jan 9, 2014
Hi Igor,
Thanks for having a look at this!
I can see everything works fine in your Plunkr and can't get it to break, so I don't know why on my case it doesn't work. The only thing I'm realising is that, on the generated HTML for my input element, angular isn't adding the ng-valid-min and ng-valid-max classes as in your Plunkr.
An adapted version of yours generated (works):
My generated HTML (doesn't work):
Resulting in:
I can't reproduce my problem in the Plunkr, so I'm at a loss.
Any ideas on what I might be doing wrong?
Deklin commentedon Feb 19, 2014
We are having this issue with 1.2.13
Here is a fiddle showing the issue. Please use chrome to test:
http://jsfiddle.net/sberube/BnE73/
Steps:
1a. Observe that value.$error.max goes to true meaning the # has failed MAX validation
2a. Observe that the $error still shows a max error when the number is now in the valid range.
3a. observe that $error.max goes to false
So the {{max}} interpolation is not re-validating the input, but changing the input causes re-validation including the new value. This is the bug we are experiencing with 1.2.13
EDIT:
We are going to see if this solves our issue until angular natively supports this:
http://jsfiddle.net/g/s5gKC/
Deklin commentedon Feb 19, 2014
Caitlin;
According to the documentation it does:
http://docs.angularjs.org/api/ng/input/input%5Bnumber%5D
On Wed, Feb 19, 2014 at 11:03 AM, Caitlin Potter
[email protected]:
rwinzhang commentedon Jun 1, 2014
The issue appears on this case http://plnkr.co/edit/4CPpJl when min and max value are dynamically set.
robjames commentedon Jun 2, 2014
I think the solution to this is the
novalidateattribute - Well, solved it for me anyway.jamie-pate commentedon Jun 2, 2014
I am currently having a related issue. In my case, when the numberInputType controller is instantiated,
attr.minand/orattr.maxevaluate asfalsy. The solution is to replaceif (attr.max)withif ('max' in attr)andif (attr.min)withif ('min' in attr)Unfortunately my employer thus far has not approved (and looks like it won't any time soon) the CLA so someone else will have to make this PR.
PS: also needs a check for NaN since attr.max could be anything during validation now.
gkocjan commentedon Jul 1, 2014
Still present in 1.2.18
28 remaining items
adrianduke commentedon Mar 19, 2015
Still experiencing this issue on v1.3.10... http://plnkr.co/edit/uS4zsh05jeP7pF7A2aVk
Using an initialisation value that isn't
nullor""resolves the issue for me e.g.$scope.max = "1"idoo commentedon Mar 19, 2015
@adrianduke try
http://plnkr.co/edit/DF4R6vfQpf909jj19sFv?p=preview
gkalpak commentedon Mar 20, 2015
BTW, this seems to have been fixed in 1.3.14 (plnkr) and 1.4.0-beta.5 (plnkr).
petebacondarwin commentedon Mar 20, 2015
It would have expected this commit to fix it - b350283
But this was already there at 1.3.0
petebacondarwin commentedon Mar 20, 2015
Ah! Fixed here: abfce53
piotrkulpinski commentedon Mar 22, 2015
@petebacondarwin WIll it be released in upcoming 1.3.16 release?
petebacondarwin commentedon Mar 23, 2015
@piotrkulpinski - this was already there in 1.3.14 and so will continue to appear in the next release too.
stewones commentedon Jul 22, 2015
+1 here 1.4.x
favio41 commentedon Jun 6, 2016
Hi guys, in the documentation is missing the attr ng-max and ng-min for input type number.
gkalpak commentedon Jun 6, 2016
Interesting! They are not documented as standalone directives either...
@favio41, would you like to submit a PR ?
User195 commentedon Jan 25, 2019
just use ng-min and ng-max
It solved all my problems!
andre719mv commentedon Feb 20, 2019
For for old Angular versions use fallback values before model is initialized:
max="{{max || 99999}}"
It worked for me.