@@ -1059,19 +1059,13 @@ var inputType = {
1059
1059
* The model for the range input must always be a `Number`.
1060
1060
*
1061
1061
* IE9 and other browsers that do not support the `range` type fall back
1062
- * to a text input without any default values for `min`, `max` and `step`. Model binding,
1063
- * validation and number parsing are nevertheless supported.
1062
+ * to a text input. Model binding, validation and number parsing are nevertheless supported.
1064
1063
*
1065
1064
* Browsers that support range (latest Chrome, Safari, Firefox, Edge) treat `input[range]`
1066
1065
* in a way that never allows the input to hold an invalid value. That means:
1067
1066
* - any non-numerical value is set to `(max + min) / 2`.
1068
1067
* - any numerical value that is less than the current min val, or greater than the current max val
1069
1068
* is set to the min / max val respectively.
1070
- * - additionally, the current `step` is respected, so the nearest value that satisfies a step
1071
- * is used.
1072
- *
1073
- * See the [HTML Spec on input[type=range]](https://www.w3.org/TR/html5/forms.html#range-state-(type=range))
1074
- * for more info.
1075
1069
*
1076
1070
* This has the following consequences for Angular:
1077
1071
*
@@ -1084,21 +1078,16 @@ var inputType = {
1084
1078
* That means the model for range will immediately be set to `50` after `ngModel` has been
1085
1079
* initialized. It also means a range input can never have the required error.
1086
1080
*
1087
- * This does not only affect changes to the model value, but also to the values of the `min`,
1088
- * `max`, and `step` attributes. When these change in a way that will cause the browser to modify
1089
- * the input value, Angular will also update the model value.
1081
+ * This does not only affect changes to the model value, but also to the values of the `min` and
1082
+ * `max` attributes. When these change in a way that will cause the browser to modify the input value,
1083
+ * Angular will also update the model value.
1090
1084
*
1091
1085
* Automatic value adjustment also means that a range input element can never have the `required`,
1092
1086
* `min`, or `max` errors.
1093
1087
*
1094
- * However, `step` is currently only fully implemented by Firefox. Other browsers have problems
1095
- * when the step value changes dynamically - they do not adjust the element value correctly, but
1096
- * instead may set the `stepMismatch` error. If that's the case, the Angular will set the `step`
1097
- * error on the input, and set the model to `undefined`.
1098
- *
1099
- * Note that `input[range]` is not compatible with `ngMax`, `ngMin`, and `ngStep`, because they do
1100
- * not set the `min` and `max` attributes, which means that the browser won't automatically adjust
1101
- * the input value based on their values, and will always assume min = 0, max = 100, and step = 1.
1088
+ * Note that `input[range]` is not compatible with`ngMax` and `ngMin`, because they do not set the
1089
+ * `min` and `max` attributes, which means that the browser won't automatically adjust the input
1090
+ * value based on their values, and will always assume min = 0 and max = 100.
1102
1091
*
1103
1092
* @param ngInputRange The presense of this attribute enables the built-in support for
1104
1093
* `input[range]`.
@@ -1108,8 +1097,6 @@ var inputType = {
1108
1097
* than `min`. Can be interpolated.
1109
1098
* @param {string= } max Sets the `max` validation to ensure that the value entered is less than `max`.
1110
1099
* Can be interpolated.
1111
- * @param {string= } step Sets the `step` validation to ensure that the value entered matches the `step`
1112
- * Can be interpolated.
1113
1100
* @param {string= } ngChange Angular expression to be executed when the ngModel value changes due
1114
1101
* to user interaction with the input element.
1115
1102
*
@@ -1536,13 +1523,6 @@ function numberFormatterParser(ctrl) {
1536
1523
} ) ;
1537
1524
}
1538
1525
1539
- function parseNumberAttrVal ( val ) {
1540
- if ( isDefined ( val ) && ! isNumber ( val ) ) {
1541
- val = parseFloat ( val ) ;
1542
- }
1543
- return ! isNumberNaN ( val ) ? val : undefined ;
1544
- }
1545
-
1546
1526
function numberInputType ( scope , element , attr , ctrl , $sniffer , $browser ) {
1547
1527
badInputChecker ( scope , element , attr , ctrl ) ;
1548
1528
baseInputType ( scope , element , attr , ctrl , $sniffer , $browser ) ;
@@ -1557,7 +1537,10 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1557
1537
} ;
1558
1538
1559
1539
attr . $observe ( 'min' , function ( val ) {
1560
- minVal = parseNumberAttrVal ( val ) ;
1540
+ if ( isDefined ( val ) && ! isNumber ( val ) ) {
1541
+ val = parseFloat ( val ) ;
1542
+ }
1543
+ minVal = isNumber ( val ) && ! isNaN ( val ) ? val : undefined ;
1561
1544
// TODO(matsko): implement validateLater to reduce number of validations
1562
1545
ctrl . $validate ( ) ;
1563
1546
} ) ;
@@ -1569,7 +1552,10 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1569
1552
} ;
1570
1553
1571
1554
attr . $observe ( 'max' , function ( val ) {
1572
- maxVal = parseNumberAttrVal ( val ) ;
1555
+ if ( isDefined ( val ) && ! isNumber ( val ) ) {
1556
+ val = parseFloat ( val ) ;
1557
+ }
1558
+ maxVal = isNumber ( val ) && ! isNaN ( val ) ? val : undefined ;
1573
1559
// TODO(matsko): implement validateLater to reduce number of validations
1574
1560
ctrl . $validate ( ) ;
1575
1561
} ) ;
@@ -1584,11 +1570,9 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1584
1570
var supportsRange = ctrl . $$hasNativeValidators && element [ 0 ] . type === 'range' ,
1585
1571
minVal = supportsRange ? 0 : undefined ,
1586
1572
maxVal = supportsRange ? 100 : undefined ,
1587
- stepVal = supportsRange ? 1 : undefined ,
1588
1573
validity = element [ 0 ] . validity ,
1589
1574
hasMinAttr = isDefined ( attr . min ) ,
1590
- hasMaxAttr = isDefined ( attr . max ) ,
1591
- hasStepAttr = isDefined ( attr . step ) ;
1575
+ hasMaxAttr = isDefined ( attr . max ) ;
1592
1576
1593
1577
var originalRender = ctrl . $render ;
1594
1578
@@ -1605,7 +1589,7 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1605
1589
ctrl . $validators . min = supportsRange ?
1606
1590
// Since all browsers set the input to a valid value, we don't need to check validity
1607
1591
function noopMinValidator ( ) { return true ; } :
1608
- // non-support browsers validate the min val
1592
+ // non-support browsers validate the range
1609
1593
function minValidator ( modelValue , viewValue ) {
1610
1594
return ctrl . $isEmpty ( viewValue ) || isUndefined ( minVal ) || viewValue >= minVal ;
1611
1595
} ;
@@ -1617,41 +1601,28 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1617
1601
ctrl . $validators . max = supportsRange ?
1618
1602
// Since all browsers set the input to a valid value, we don't need to check validity
1619
1603
function noopMaxValidator ( ) { return true ; } :
1620
- // non-support browsers validate the max val
1604
+ // ngMax doesn't set the max attr, so the browser doesn't adjust the input value as setting max would
1621
1605
function maxValidator ( modelValue , viewValue ) {
1622
1606
return ctrl . $isEmpty ( viewValue ) || isUndefined ( maxVal ) || viewValue <= maxVal ;
1623
1607
} ;
1624
1608
1625
1609
setInitialValueAndObserver ( 'max' , maxChange ) ;
1626
1610
}
1627
1611
1628
- if ( hasStepAttr ) {
1629
- ctrl . $validators . step = supportsRange ?
1630
- function nativeStepValidator ( ) {
1631
- // Currently, only FF implements the spec on step change correctly (i.e. adjusting the
1632
- // input element value to a valid value). It's possible that other browsers set the stepMismatch
1633
- // validity error instead, so we can at least report an error in that case.
1634
- return ! validity . stepMismatch ;
1635
- } :
1636
- // ngStep doesn't set the setp attr, so the browser doesn't adjust the input value as setting step would
1637
- function stepValidator ( modelValue , viewValue ) {
1638
- return ctrl . $isEmpty ( viewValue ) || isUndefined ( stepVal ) ||
1639
- isValidForStep ( viewValue , minVal || 0 , stepVal ) ;
1640
- } ;
1641
-
1642
- setInitialValueAndObserver ( 'step' , stepChange ) ;
1643
- }
1644
-
1645
1612
function setInitialValueAndObserver ( htmlAttrName , changeFn ) {
1646
1613
// interpolated attributes set the attribute value only after a digest, but we need the
1647
1614
// attribute value when the input is first rendered, so that the browser can adjust the
1648
1615
// input value based on the min/max value
1649
1616
element . attr ( htmlAttrName , attr [ htmlAttrName ] ) ;
1617
+
1650
1618
attr . $observe ( htmlAttrName , changeFn ) ;
1651
1619
}
1652
1620
1653
1621
function minChange ( val ) {
1654
- minVal = parseNumberAttrVal ( val ) ;
1622
+ if ( isDefined ( val ) && ! isNumber ( val ) ) {
1623
+ val = parseFloat ( val ) ;
1624
+ }
1625
+ minVal = isNumber ( val ) && ! isNaN ( val ) ? val : undefined ;
1655
1626
// ignore changes before model is initialized
1656
1627
if ( isNumberNaN ( ctrl . $modelValue ) ) {
1657
1628
return ;
@@ -1672,7 +1643,10 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1672
1643
}
1673
1644
1674
1645
function maxChange ( val ) {
1675
- maxVal = parseNumberAttrVal ( val ) ;
1646
+ if ( isDefined ( val ) && ! isNumber ( val ) ) {
1647
+ val = parseFloat ( val ) ;
1648
+ }
1649
+ maxVal = isNumber ( val ) && ! isNaN ( val ) ? val : undefined ;
1676
1650
// ignore changes before model is initialized
1677
1651
if ( isNumberNaN ( ctrl . $modelValue ) ) {
1678
1652
return ;
@@ -1693,21 +1667,6 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1693
1667
}
1694
1668
}
1695
1669
1696
- function stepChange ( val ) {
1697
- stepVal = parseNumberAttrVal ( val ) ;
1698
- // ignore changes before model is initialized
1699
- if ( isNumberNaN ( ctrl . $modelValue ) ) {
1700
- return ;
1701
- }
1702
-
1703
- // Some browsers don't adjust the input value correctly, but set the stepMismatch error
1704
- if ( supportsRange && ctrl . $viewValue !== element . val ( ) ) {
1705
- ctrl . $setViewValue ( element . val ( ) ) ;
1706
- } else {
1707
- // TODO(matsko): implement validateLater to reduce number of validations
1708
- ctrl . $validate ( ) ;
1709
- }
1710
- }
1711
1670
}
1712
1671
1713
1672
function urlInputType ( scope , element , attr , ctrl , $sniffer , $browser ) {
0 commit comments