@@ -16,9 +16,9 @@ var inputType = {
16
16
* @param {string } ngModel Assignable angular expression to data-bind to.
17
17
* @param {string= } name Property name of the form under which the control is published.
18
18
* @param {string= } required Sets `required` validation error key if the value is not entered.
19
- * @param {number = } ngMinlength Sets `minlength` validation error key if the value is shorter than
19
+ * @param {expression = } ngMinlength Sets `minlength` validation error key if the value is shorter than
20
20
* minlength.
21
- * @param {number = } ngMaxlength Sets `maxlength` validation error key if the value is longer than
21
+ * @param {expression = } ngMaxlength Sets `maxlength` validation error key if the value is longer than
22
22
* maxlength.
23
23
* @param {string= } ngPattern Sets `pattern` validation error key if the value does not match the
24
24
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
@@ -93,9 +93,9 @@ var inputType = {
93
93
* @param {string= } min Sets the `min` validation error key if the value entered is less then `min`.
94
94
* @param {string= } max Sets the `max` validation error key if the value entered is greater then `min`.
95
95
* @param {string= } required Sets `required` validation error key if the value is not entered.
96
- * @param {number = } ngMinlength Sets `minlength` validation error key if the value is shorter than
96
+ * @param {expression = } ngMinlength Sets `minlength` validation error key if the value is shorter than
97
97
* minlength.
98
- * @param {number = } ngMaxlength Sets `maxlength` validation error key if the value is longer than
98
+ * @param {expression = } ngMaxlength Sets `maxlength` validation error key if the value is longer than
99
99
* maxlength.
100
100
* @param {string= } ngPattern Sets `pattern` validation error key if the value does not match the
101
101
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
@@ -159,9 +159,9 @@ var inputType = {
159
159
* @param {string } ngModel Assignable angular expression to data-bind to.
160
160
* @param {string= } name Property name of the form under which the control is published.
161
161
* @param {string= } required Sets `required` validation error key if the value is not entered.
162
- * @param {number = } ngMinlength Sets `minlength` validation error key if the value is shorter than
162
+ * @param {expression = } ngMinlength Sets `minlength` validation error key if the value is shorter than
163
163
* minlength.
164
- * @param {number = } ngMaxlength Sets `maxlength` validation error key if the value is longer than
164
+ * @param {expression = } ngMaxlength Sets `maxlength` validation error key if the value is longer than
165
165
* maxlength.
166
166
* @param {string= } ngPattern Sets `pattern` validation error key if the value does not match the
167
167
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
@@ -224,9 +224,9 @@ var inputType = {
224
224
* @param {string } ngModel Assignable angular expression to data-bind to.
225
225
* @param {string= } name Property name of the form under which the control is published.
226
226
* @param {string= } required Sets `required` validation error key if the value is not entered.
227
- * @param {number = } ngMinlength Sets `minlength` validation error key if the value is shorter than
227
+ * @param {expression = } ngMinlength Sets `minlength` validation error key if the value is shorter than
228
228
* minlength.
229
- * @param {number = } ngMaxlength Sets `maxlength` validation error key if the value is longer than
229
+ * @param {expression = } ngMaxlength Sets `maxlength` validation error key if the value is longer than
230
230
* maxlength.
231
231
* @param {string= } ngPattern Sets `pattern` validation error key if the value does not match the
232
232
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
@@ -460,39 +460,30 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
460
460
ctrl . $parsers . push ( patternValidator ) ;
461
461
}
462
462
463
- // min length validator
464
- if ( attr . ngMinlength ) {
465
- var minlength = int ( attr . ngMinlength ) ;
466
- var minLengthValidator = function ( value ) {
467
- if ( ! isEmpty ( value ) && value . length < minlength ) {
468
- ctrl . $setValidity ( 'minlength' , false ) ;
469
- return undefined ;
470
- } else {
471
- ctrl . $setValidity ( 'minlength' , true ) ;
472
- return value ;
473
- }
474
- } ;
475
-
476
- ctrl . $parsers . push ( minLengthValidator ) ;
477
- ctrl . $formatters . push ( minLengthValidator ) ;
478
- }
463
+ function applyMinMaxLength ( minOrMax , langthInvalid ) {
464
+ if ( attr . hasOwnProperty ( minOrMax ) ) {
465
+ var validityValue = minOrMax === 'ngMinlength' ? 'minlength' : 'maxlength' ;
466
+ var validator = function ( value ) {
467
+ var parsedValue = parseFloat ( attr [ minOrMax ] , 10 ) ;
468
+ if ( ! isEmpty ( value ) && langthInvalid ( value , parsedValue ) ) {
469
+ ctrl . $setValidity ( validityValue , false ) ;
470
+ return undefined ;
471
+ } else {
472
+ ctrl . $setValidity ( validityValue , true ) ;
473
+ return value ;
474
+ }
475
+ } ;
479
476
480
- // max length validator
481
- if ( attr . ngMaxlength ) {
482
- var maxlength = int ( attr . ngMaxlength ) ;
483
- var maxLengthValidator = function ( value ) {
484
- if ( ! isEmpty ( value ) && value . length > maxlength ) {
485
- ctrl . $setValidity ( 'maxlength' , false ) ;
486
- return undefined ;
487
- } else {
488
- ctrl . $setValidity ( 'maxlength' , true ) ;
489
- return value ;
490
- }
491
- } ;
477
+ ctrl . $parsers . push ( validator ) ;
478
+ ctrl . $formatters . push ( validator ) ;
492
479
493
- ctrl . $parsers . push ( maxLengthValidator ) ;
494
- ctrl . $formatters . push ( maxLengthValidator ) ;
480
+ attr . $observe ( minOrMax , function ( ) {
481
+ ctrl . $setViewValue ( ctrl . $viewValue ) ;
482
+ } ) ;
483
+ }
495
484
}
485
+ applyMinMaxLength ( 'ngMinlength' , function langthInvalid ( value , min ) { return value . length < min ; } ) ;
486
+ applyMinMaxLength ( 'ngMaxlength' , function langthInvalid ( value , max ) { return value . length > max ; } ) ;
496
487
}
497
488
498
489
function numberInputType ( scope , element , attr , ctrl , $sniffer , $browser ) {
@@ -653,9 +644,9 @@ function checkboxInputType(scope, element, attr, ctrl) {
653
644
* @param {string } ngModel Assignable angular expression to data-bind to.
654
645
* @param {string= } name Property name of the form under which the control is published.
655
646
* @param {string= } required Sets `required` validation error key if the value is not entered.
656
- * @param {number = } ngMinlength Sets `minlength` validation error key if the value is shorter than
647
+ * @param {expression = } ngMinlength Sets `minlength` validation error key if the value is shorter than
657
648
* minlength.
658
- * @param {number = } ngMaxlength Sets `maxlength` validation error key if the value is longer than
649
+ * @param {expression = } ngMaxlength Sets `maxlength` validation error key if the value is longer than
659
650
* maxlength.
660
651
* @param {string= } ngPattern Sets `pattern` validation error key if the value does not match the
661
652
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
@@ -677,9 +668,9 @@ function checkboxInputType(scope, element, attr, ctrl) {
677
668
* @param {string } ngModel Assignable angular expression to data-bind to.
678
669
* @param {string= } name Property name of the form under which the control is published.
679
670
* @param {string= } required Sets `required` validation error key if the value is not entered.
680
- * @param {number = } ngMinlength Sets `minlength` validation error key if the value is shorter than
671
+ * @param {expression = } ngMinlength Sets `minlength` validation error key if the value is shorter than
681
672
* minlength.
682
- * @param {number = } ngMaxlength Sets `maxlength` validation error key if the value is longer than
673
+ * @param {expression = } ngMaxlength Sets `maxlength` validation error key if the value is longer than
683
674
* maxlength.
684
675
* @param {string= } ngPattern Sets `pattern` validation error key if the value does not match the
685
676
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
0 commit comments