This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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 #6750
- Loading branch information
Showing
3 changed files
with
81 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 |
---|---|---|
|
@@ -1000,22 +1000,6 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) { | |
return ctrl.$isEmpty(value) || isUndefined(regexp) || regexp.test(value); | ||
}; | ||
} | ||
|
||
// 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) { | ||
|
@@ -2183,6 +2167,43 @@ var requiredDirective = function() { | |
}; | ||
|
||
|
||
var maxlengthDirective = function() { | ||
return { | ||
require: '?ngModel', | ||
link: function(scope, elm, attr, ctrl) { | ||
if (!ctrl) return; | ||
|
||
var maxlength = 0; | ||
attr.$observe('maxlength', function(value) { | ||
maxlength = int(value) || 0; | ||
ctrl.$validate(); | ||
}); | ||
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 = 0; | ||
attr.$observe('minlength', function(value) { | ||
minlength = int(value) || 0; | ||
ctrl.$validate(); | ||
}); | ||
ctrl.$validators.minlength = function(value) { | ||
return ctrl.$isEmpty(value) || value.length >= minlength; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
VRMink
|
||
}; | ||
} | ||
}; | ||
}; | ||
|
||
|
||
/** | ||
* @ngdoc directive | ||
* @name ngList | ||
|
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
Why is the value valid when it is empty? Empty means basically it has no length, which makes this invalid, no?
edit. Nevermind, I see the logic is that if the value is empty it is valid, and if you need the value you use required.