@@ -1027,132 +1027,6 @@ var inputType = {
1027
1027
*/
1028
1028
'radio' : radioInputType ,
1029
1029
1030
- /**
1031
- * @ngdoc input
1032
- * @name input[range]
1033
- *
1034
- * @description
1035
- * Native range input with validation and transformation.
1036
- *
1037
- * <div class="alert alert-warning">
1038
- * <p>
1039
- * In v1.5.9+, in order to avoid interfering with already existing, custom directives for
1040
- * `input[range]`, you need to let Angular know that you want to enable its built-in support.
1041
- * You can do this by adding the `ng-input-range` attribute to the input element. E.g.:
1042
- * `<input type="range" ng-input-range ... />`
1043
- * </p><br />
1044
- * <p>
1045
- * Input elements without the `ng-input-range` attibute will continue to be treated the same
1046
- * as in previous versions (e.g. their model value will be a string not a number and Angular
1047
- * will not take `min`/`max`/`step` attributes and properties into account).
1048
- * </p><br />
1049
- * <p>
1050
- * **Note:** From v1.6.x onwards, the support for `input[range]` will be always enabled and
1051
- * the `ng-input-range` attribute will have no effect.
1052
- * </p><br />
1053
- * <p>
1054
- * This documentation page refers to elements which have the built-in support enabled; i.e.
1055
- * elements _with_ the `ng-input-range` attribute.
1056
- * </p>
1057
- * </div>
1058
- *
1059
- * The model for the range input must always be a `Number`.
1060
- *
1061
- * IE9 and other browsers that do not support the `range` type fall back
1062
- * to a text input. Model binding, validation and number parsing are nevertheless supported.
1063
- *
1064
- * Browsers that support range (latest Chrome, Safari, Firefox, Edge) treat `input[range]`
1065
- * in a way that never allows the input to hold an invalid value. That means:
1066
- * - any non-numerical value is set to `(max + min) / 2`.
1067
- * - any numerical value that is less than the current min val, or greater than the current max val
1068
- * is set to the min / max val respectively.
1069
- *
1070
- * This has the following consequences for Angular:
1071
- *
1072
- * Since the element value should always reflect the current model value, a range input
1073
- * will set the bound ngModel expression to the value that the browser has set for the
1074
- * input element. For example, in the following input `<input type="range" ng-input-range ng-model="model.value">`,
1075
- * if the application sets `model.value = null`, the browser will set the input to `'50'`.
1076
- * Angular will then set the model to `50`, to prevent input and model value being out of sync.
1077
- *
1078
- * That means the model for range will immediately be set to `50` after `ngModel` has been
1079
- * initialized. It also means a range input can never have the required error.
1080
- *
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.
1084
- *
1085
- * Automatic value adjustment also means that a range input element can never have the `required`,
1086
- * `min`, or `max` errors.
1087
- *
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.
1091
- *
1092
- * @param ngInputRange The presense of this attribute enables the built-in support for
1093
- * `input[range]`.
1094
- * @param {string } ngModel Assignable angular expression to data-bind to.
1095
- * @param {string= } name Property name of the form under which the control is published.
1096
- * @param {string= } min Sets the `min` validation to ensure that the value entered is greater
1097
- * than `min`. Can be interpolated.
1098
- * @param {string= } max Sets the `max` validation to ensure that the value entered is less than `max`.
1099
- * Can be interpolated.
1100
- * @param {string= } ngChange Angular expression to be executed when the ngModel value changes due
1101
- * to user interaction with the input element.
1102
- *
1103
- * @example
1104
- <example name="range-input-directive" module="rangeExample">
1105
- <file name="index.html">
1106
- <script>
1107
- angular.module('rangeExample', [])
1108
- .controller('ExampleController', ['$scope', function($scope) {
1109
- $scope.value = 75;
1110
- $scope.min = 10;
1111
- $scope.max = 90;
1112
- }]);
1113
- </script>
1114
- <form name="myForm" ng-controller="ExampleController">
1115
-
1116
- Model as range: <input type="range" ng-input-range name="range" ng-model="value" min="{{min}}" max="{{max}}">
1117
- <hr>
1118
- Model as number: <input type="number" ng-model="value"><br>
1119
- Min: <input type="number" ng-model="min"><br>
1120
- Max: <input type="number" ng-model="max"><br>
1121
- value = <code>{{value}}</code><br/>
1122
- myForm.range.$valid = <code>{{myForm.range.$valid}}</code><br/>
1123
- myForm.range.$error = <code>{{myForm.range.$error}}</code>
1124
- </form>
1125
- </file>
1126
- </example>
1127
-
1128
- * ## Range Input with ngMin & ngMax attributes
1129
-
1130
- * @example
1131
- <example name="range-input-directive-ng" module="rangeExample">
1132
- <file name="index.html">
1133
- <script>
1134
- angular.module('rangeExample', [])
1135
- .controller('ExampleController', ['$scope', function($scope) {
1136
- $scope.value = 75;
1137
- $scope.min = 10;
1138
- $scope.max = 90;
1139
- }]);
1140
- </script>
1141
- <form name="myForm" ng-controller="ExampleController">
1142
- Model as range: <input type="range" ng-input-range name="range" ng-model="value" ng-min="min" ng-max="max">
1143
- <hr>
1144
- Model as number: <input type="number" ng-model="value"><br>
1145
- Min: <input type="number" ng-model="min"><br>
1146
- Max: <input type="number" ng-model="max"><br>
1147
- value = <code>{{value}}</code><br/>
1148
- myForm.range.$valid = <code>{{myForm.range.$valid}}</code><br/>
1149
- myForm.range.$error = <code>{{myForm.range.$error}}</code>
1150
- </form>
1151
- </file>
1152
- </example>
1153
-
1154
- */
1155
- 'range' : rangeInputType ,
1156
1030
1157
1031
/**
1158
1032
* @ngdoc input
@@ -1504,7 +1378,10 @@ function badInputChecker(scope, element, attr, ctrl) {
1504
1378
}
1505
1379
}
1506
1380
1507
- function numberFormatterParser ( ctrl ) {
1381
+ function numberInputType ( scope , element , attr , ctrl , $sniffer , $browser ) {
1382
+ badInputChecker ( scope , element , attr , ctrl ) ;
1383
+ baseInputType ( scope , element , attr , ctrl , $sniffer , $browser ) ;
1384
+
1508
1385
ctrl . $$parserName = 'number' ;
1509
1386
ctrl . $parsers . push ( function ( value ) {
1510
1387
if ( ctrl . $isEmpty ( value ) ) return null ;
@@ -1521,17 +1398,9 @@ function numberFormatterParser(ctrl) {
1521
1398
}
1522
1399
return value ;
1523
1400
} ) ;
1524
- }
1525
-
1526
- function numberInputType ( scope , element , attr , ctrl , $sniffer , $browser ) {
1527
- badInputChecker ( scope , element , attr , ctrl ) ;
1528
- baseInputType ( scope , element , attr , ctrl , $sniffer , $browser ) ;
1529
- numberFormatterParser ( ctrl ) ;
1530
-
1531
- var minVal ;
1532
- var maxVal ;
1533
1401
1534
1402
if ( isDefined ( attr . min ) || attr . ngMin ) {
1403
+ var minVal ;
1535
1404
ctrl . $validators . min = function ( value ) {
1536
1405
return ctrl . $isEmpty ( value ) || isUndefined ( minVal ) || value >= minVal ;
1537
1406
} ;
@@ -1547,6 +1416,7 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1547
1416
}
1548
1417
1549
1418
if ( isDefined ( attr . max ) || attr . ngMax ) {
1419
+ var maxVal ;
1550
1420
ctrl . $validators . max = function ( value ) {
1551
1421
return ctrl . $isEmpty ( value ) || isUndefined ( maxVal ) || value <= maxVal ;
1552
1422
} ;
@@ -1562,113 +1432,6 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
1562
1432
}
1563
1433
}
1564
1434
1565
- function rangeInputType ( scope , element , attr , ctrl , $sniffer , $browser ) {
1566
- badInputChecker ( scope , element , attr , ctrl ) ;
1567
- numberFormatterParser ( ctrl ) ;
1568
- baseInputType ( scope , element , attr , ctrl , $sniffer , $browser ) ;
1569
-
1570
- var supportsRange = ctrl . $$hasNativeValidators && element [ 0 ] . type === 'range' ,
1571
- minVal = supportsRange ? 0 : undefined ,
1572
- maxVal = supportsRange ? 100 : undefined ,
1573
- validity = element [ 0 ] . validity ,
1574
- hasMinAttr = isDefined ( attr . min ) ,
1575
- hasMaxAttr = isDefined ( attr . max ) ;
1576
-
1577
- var originalRender = ctrl . $render ;
1578
-
1579
- ctrl . $render = supportsRange && isDefined ( validity . rangeUnderflow ) && isDefined ( validity . rangeOverflow ) ?
1580
- //Browsers that implement range will set these values automatically, but reading the adjusted values after
1581
- //$render would cause the min / max validators to be applied with the wrong value
1582
- function rangeRender ( ) {
1583
- originalRender ( ) ;
1584
- ctrl . $setViewValue ( element . val ( ) ) ;
1585
- } :
1586
- originalRender ;
1587
-
1588
- if ( hasMinAttr ) {
1589
- ctrl . $validators . min = supportsRange ?
1590
- // Since all browsers set the input to a valid value, we don't need to check validity
1591
- function noopMinValidator ( ) { return true ; } :
1592
- // non-support browsers validate the range
1593
- function minValidator ( modelValue , viewValue ) {
1594
- return ctrl . $isEmpty ( viewValue ) || isUndefined ( minVal ) || viewValue >= minVal ;
1595
- } ;
1596
-
1597
- setInitialValueAndObserver ( 'min' , minChange ) ;
1598
- }
1599
-
1600
- if ( hasMaxAttr ) {
1601
- ctrl . $validators . max = supportsRange ?
1602
- // Since all browsers set the input to a valid value, we don't need to check validity
1603
- function noopMaxValidator ( ) { return true ; } :
1604
- // ngMax doesn't set the max attr, so the browser doesn't adjust the input value as setting max would
1605
- function maxValidator ( modelValue , viewValue ) {
1606
- return ctrl . $isEmpty ( viewValue ) || isUndefined ( maxVal ) || viewValue <= maxVal ;
1607
- } ;
1608
-
1609
- setInitialValueAndObserver ( 'max' , maxChange ) ;
1610
- }
1611
-
1612
- function setInitialValueAndObserver ( htmlAttrName , changeFn ) {
1613
- // interpolated attributes set the attribute value only after a digest, but we need the
1614
- // attribute value when the input is first rendered, so that the browser can adjust the
1615
- // input value based on the min/max value
1616
- element . attr ( htmlAttrName , attr [ htmlAttrName ] ) ;
1617
-
1618
- attr . $observe ( htmlAttrName , changeFn ) ;
1619
- }
1620
-
1621
- function minChange ( val ) {
1622
- if ( isDefined ( val ) && ! isNumber ( val ) ) {
1623
- val = parseFloat ( val ) ;
1624
- }
1625
- minVal = isNumber ( val ) && ! isNaN ( val ) ? val : undefined ;
1626
- // ignore changes before model is initialized
1627
- if ( isNumberNaN ( ctrl . $modelValue ) ) {
1628
- return ;
1629
- }
1630
-
1631
- if ( supportsRange ) {
1632
- var elVal = element . val ( ) ;
1633
- // IE11 doesn't set the el val correctly if the minVal is greater than the element value
1634
- if ( minVal > elVal ) {
1635
- elVal = minVal ;
1636
- element . val ( elVal ) ;
1637
- }
1638
- ctrl . $setViewValue ( elVal ) ;
1639
- } else {
1640
- // TODO(matsko): implement validateLater to reduce number of validations
1641
- ctrl . $validate ( ) ;
1642
- }
1643
- }
1644
-
1645
- function maxChange ( val ) {
1646
- if ( isDefined ( val ) && ! isNumber ( val ) ) {
1647
- val = parseFloat ( val ) ;
1648
- }
1649
- maxVal = isNumber ( val ) && ! isNaN ( val ) ? val : undefined ;
1650
- // ignore changes before model is initialized
1651
- if ( isNumberNaN ( ctrl . $modelValue ) ) {
1652
- return ;
1653
- }
1654
-
1655
- if ( supportsRange ) {
1656
- var elVal = element . val ( ) ;
1657
- // IE11 doesn't set the el val correctly if the maxVal is less than the element value
1658
- if ( maxVal < elVal ) {
1659
- element . val ( maxVal ) ;
1660
- // IE11 and Chrome don't set the value to the minVal when max < min
1661
- elVal = maxVal < minVal ? minVal : maxVal ;
1662
- }
1663
- ctrl . $setViewValue ( elVal ) ;
1664
- } else {
1665
- // TODO(matsko): implement validateLater to reduce number of validations
1666
- ctrl . $validate ( ) ;
1667
- }
1668
- }
1669
-
1670
- }
1671
-
1672
1435
function urlInputType ( scope , element , attr , ctrl , $sniffer , $browser ) {
1673
1436
// Note: no badInputChecker here by purpose as `url` is only a validation
1674
1437
// in browsers, i.e. we can always read out input.value even if it is not valid!
0 commit comments