@@ -1061,23 +1061,18 @@ var inputType = {
1061
1061
* Angular will also update the model value.
1062
1062
*
1063
1063
* Automatic value adjustment also means that a range input element can never have the `required`,
1064
- * `min`, or `max` errors, except when using `ngMax` and `ngMin`, which are not affected by automatic
1065
- * value adjustment, because they do not set the `min` and `max` attributes.
1064
+ * `min`, or `max` errors.
1065
+ *
1066
+ * Note that `input[range]` is not compatible with`ngMax` and `ngMin`, because they do not set the
1067
+ * `min` and `max` attributes, which means that the browser won't automatically adjust the input
1068
+ * value based on their values, and will always assume min = 0 and max = 100.
1066
1069
*
1067
1070
* @param {string } ngModel Assignable angular expression to data-bind to.
1068
1071
* @param {string= } name Property name of the form under which the control is published.
1069
1072
* @param {string= } min Sets the `min` validation to ensure that the value entered is greater
1070
1073
* than `min`. Can be interpolated.
1071
1074
* @param {string= } max Sets the `max` validation to ensure that the value entered is less than `max`.
1072
1075
* Can be interpolated.
1073
- * @param {string= } ngMin Takes an expression. Sets the `min` validation to ensure that the value
1074
- * entered is greater than `min`. Does not set the `min` attribute and therefore
1075
- * adds no native HTML5 validation. It also means the browser won't adjust the
1076
- * element value in case `min` is greater than the current value.
1077
- * @param {string= } ngMax Takes an expression. Sets the `max` validation to ensure that the value
1078
- * entered is less than `max`. Does not set the `max` attribute and therefore
1079
- * adds no native HTML5 validation. It also means the browser won't adjust the
1080
- * element value in case `max` is less than the current value.
1081
1076
* @param {string= } ngChange Angular expression to be executed when the ngModel value changes due
1082
1077
* to user interaction with the input element.
1083
1078
*
@@ -1551,8 +1546,8 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1551
1546
minVal = supportsRange ? 0 : undefined ,
1552
1547
maxVal = supportsRange ? 100 : undefined ,
1553
1548
validity = element [ 0 ] . validity ,
1554
- minAttrType = isDefined ( attr . ngMin ) ? 'ngMin' : isDefined ( attr . min ) ? 'min' : false ,
1555
- maxAttrType = isDefined ( attr . ngMax ) ? 'ngMax' : isDefined ( attr . max ) ? 'max' : false ;
1549
+ hasMinAttr = isDefined ( attr . min ) ,
1550
+ hasMaxAttr = isDefined ( attr . max ) ;
1556
1551
1557
1552
var originalRender = ctrl . $render ;
1558
1553
@@ -1565,38 +1560,35 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1565
1560
} :
1566
1561
originalRender ;
1567
1562
1568
- if ( minAttrType ) {
1569
- ctrl . $validators . min = minAttrType === 'min' && supportsRange ?
1563
+ if ( hasMinAttr ) {
1564
+ ctrl . $validators . min = supportsRange ?
1570
1565
// Since all browsers set the input to a valid value, we don't need to check validity
1571
1566
function noopMinValidator ( ) { return true ; } :
1572
- // ngMin doesn't set the min attr, so the browser doesn't adjust the input value as setting min would
1567
+ // non-support browsers validate the range
1573
1568
function minValidator ( modelValue , viewValue ) {
1574
1569
return ctrl . $isEmpty ( viewValue ) || isUndefined ( minVal ) || viewValue >= minVal ;
1575
1570
} ;
1576
1571
1577
- setInitialValueAndObserver ( minAttrType , 'min' , minChange ) ;
1572
+ setInitialValueAndObserver ( 'min' , minChange ) ;
1578
1573
}
1579
1574
1580
- if ( maxAttrType ) {
1581
- ctrl . $validators . max = maxAttrType === 'max' && supportsRange ?
1575
+ if ( hasMaxAttr ) {
1576
+ ctrl . $validators . max = supportsRange ?
1582
1577
// Since all browsers set the input to a valid value, we don't need to check validity
1583
1578
function noopMaxValidator ( ) { return true ; } :
1584
1579
// ngMax doesn't set the max attr, so the browser doesn't adjust the input value as setting max would
1585
1580
function maxValidator ( modelValue , viewValue ) {
1586
1581
return ctrl . $isEmpty ( viewValue ) || isUndefined ( maxVal ) || viewValue <= maxVal ;
1587
1582
} ;
1588
1583
1589
- setInitialValueAndObserver ( maxAttrType , 'max' , maxChange ) ;
1584
+ setInitialValueAndObserver ( 'max' , maxChange ) ;
1590
1585
}
1591
1586
1592
- function setInitialValueAndObserver ( actualAttrName , htmlAttrName , changeFn ) {
1593
- // e.g. max === max
1594
- if ( actualAttrName === htmlAttrName ) {
1595
- // interpolated attributes set the attribute value only after a digest, but we need the
1596
- // attribute value when the input is first rendered, so that the browser can adjust the
1597
- // input value based on the min/max value
1598
- element . attr ( htmlAttrName , attr [ htmlAttrName ] ) ;
1599
- }
1587
+ function setInitialValueAndObserver ( htmlAttrName , changeFn ) {
1588
+ // interpolated attributes set the attribute value only after a digest, but we need the
1589
+ // attribute value when the input is first rendered, so that the browser can adjust the
1590
+ // input value based on the min/max value
1591
+ element . attr ( htmlAttrName , attr [ htmlAttrName ] ) ;
1600
1592
1601
1593
attr . $observe ( htmlAttrName , changeFn ) ;
1602
1594
}
@@ -1611,7 +1603,7 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1611
1603
return ;
1612
1604
}
1613
1605
1614
- if ( supportsRange && minAttrType === 'min' ) {
1606
+ if ( supportsRange ) {
1615
1607
var elVal = element . val ( ) ;
1616
1608
// IE11 doesn't set the el val correctly if the minVal is greater than the element value
1617
1609
if ( minVal > elVal ) {
@@ -1635,7 +1627,7 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1635
1627
return ;
1636
1628
}
1637
1629
1638
- if ( supportsRange && maxAttrType === 'max' ) {
1630
+ if ( supportsRange ) {
1639
1631
var elVal = element . val ( ) ;
1640
1632
// IE11 doesn't set the el val correctly if the maxVal is less than the element value
1641
1633
if ( maxVal < elVal ) {
0 commit comments