forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(NgModel): make ngMinlength and ngMaxlength as standalone directives
Fixes angular#6750
- Loading branch information
Showing
2 changed files
with
31 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1011,22 +1011,6 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) { | |
}; | ||
} | ||
} | ||
|
||
// min length validator | ||
if (attr.ngMinlength) { | ||
var minlength = int(attr.ngMinlength); | ||
ctrl.$validators.minlength = function(value) { | ||
return ctrl.$isEmpty(value) || value.length >= minlength; | ||
}; | ||
} | ||
|
||
// max length validator | ||
if (attr.ngMaxlength) { | ||
var maxlength = int(attr.ngMaxlength); | ||
ctrl.$validators.maxlength = function(value) { | ||
return ctrl.$isEmpty(value) || value.length <= maxlength; | ||
}; | ||
} | ||
} | ||
|
||
function weekParser(isoWeek) { | ||
|
@@ -2134,6 +2118,33 @@ var requiredDirective = function() { | |
}; | ||
|
||
|
||
var maxlengthDirective = function() { | ||
return { | ||
require: '?ngModel', | ||
link: function(scope, elm, attr, ctrl) { | ||
if (!ctrl) return; | ||
var maxlength = int(attr.ngMaxlength); | ||
ctrl.$validators.maxlength = function(value) { | ||
return ctrl.$isEmpty(value) || value.length <= maxlength; | ||
}; | ||
} | ||
}; | ||
}; | ||
|
||
var minlengthDirective = function() { | ||
return { | ||
require: '?ngModel', | ||
link: function(scope, elm, attr, ctrl) { | ||
if (!ctrl) return; | ||
var minlength = int(attr.ngMinlength); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Narretz
|
||
ctrl.$validators.minlength = function(value) { | ||
return ctrl.$isEmpty(value) || value.length >= minlength; | ||
}; | ||
} | ||
}; | ||
}; | ||
|
||
|
||
/** | ||
* @ngdoc directive | ||
* @name ngList | ||
|
this means that minlength can't change once we link. Wasn't the attribute previously observed and updated every time it changed? I'm pretty sure we used to support min/max length dynamically changing. If that was the case before, we should preserve it.