-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(input): create max and/or min validation whatever the initial value is #10327
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA) at https://cla.developers.google.com/. If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check the information on your CLA or see this help article on setting the email on your git commits. Once you've done that, please reply here to let us know. If you signed the CLA as a corporation, please let us know the company's name. |
I've signed a CLA now. |
CLAs look good, thanks! |
3b8460e
to
694eb1a
Compare
Thanks! Can you add the following: an except after you change the input the first time, and change the tests for ngmin and ngmax accordingly. Even though they are not affected, it's good to have these tests. |
6a89329
to
8e3c0cd
Compare
I've updated the PR . |
compileInput('<input type="number" ng-model="value" name="alias" min="{{min}}" />'); | ||
expect(inputElm).toBeValid(); | ||
|
||
changeInputValueTo('15'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add an expect here (to all the changed tests)? We should make sure that the validator does the right thing when the min/max value is undefined and the input value is changed for the first time
Since we are fixing this, lets do it right:
|
pretty weird, why do the ngMin test use |
@Narretz: Not weird, but unexpected 😄 It is because forEach(ALIASED_ATTR, function(htmlAttr, ngAttr) {// htmlAttr -> 'min' | ngAttr -> 'ngMin'
ngAttributeAliasDirectives[ngAttr] = function() {
return {
priority: 100,
link: function(scope, element, attr) {
...
scope.$watch(attr[ngAttr], ...);
}
... |
I think the reason why ngMin test use ALIASED_ATTR define at jqLite.js#L525 var ALIASED_ATTR = {
'ngMinlength': 'minlength',
'ngMaxlength': 'maxlength',
'ngMin': 'min',
'ngMax': 'max',
'ngPattern': 'pattern'
}; Now we get the list: input[number]: min/max/ngMin/ngMax Any missed? |
Weird fact 1: I can't find any documentation on Weird fact 2: Looking at the code, So, theoretically, we don't need the @Narretz: WDYT ? |
Be aware that max/min is an attribute of DOM, different from which has |
…ue is - fix issue angular#10307 - change tests to corresponding changes - also change tests for ngmax and ngmin (though they have no some issue) Closes angular#10307
8e3c0cd
to
d289968
Compare
@tobyee: Hm...I 'm pretty aware of that :) |
@gkalpak Given that, I think we should tests both. |
@tobyee: I don't know why they aren't documented, but there is an important difference between them: In any case, I think we should have tests for both, but checking |
@gkalpak var app = angular.module("foo",[]);
app.directive("myTest", function(){
return {
template: '<div><input type="number" max="{{maxval}}"></div>',
scope: {},
link: function(scope, elm, attr){
//xxx
}
}
}); It's reasonable to do that, because the max attribute is a part of html. If use attr.$observe('max', function(val) {
if (isDefined(val) && !isNumber(val)) {
val = parseFloat(val, 10);
}
maxVal = isNumber(val) && !isNaN(val) ? val : undefined;
// TODO(matsko): implement validateLater to reduce number of validations
ctrl.$validate();
}); And more, if we treat |
Should I send a PR to fix this issue in 1.2.x ? |
Hi @tobyee, sorry for the late response. 1.2.x only receives security fixes, so we won't backport it. In the commit message it says:
|
Yes, I
|
Closes #10307