Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 4c05f61

Browse files
committed
address gkalpak's comments
1 parent 2c225f4 commit 4c05f61

File tree

3 files changed

+57
-63
lines changed

3 files changed

+57
-63
lines changed

karma-shared.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = function(config, specificOptions) {
1717
testName: specificOptions.testName || 'AngularJS',
1818
startConnect: true,
1919
options: {
20-
// We need selenium version +2.46 for 'Firefox' 39 and the last selenium version for OS X is 2.45.
20+
// We need selenium version +2.46 for Firefox 39 and the last selenium version for OS X is 2.45.
2121
// TODO: Uncomment when there is a selenium 2.46 available for OS X.
2222
// 'selenium-version': '2.46.0'
2323
}

src/ng/directive/input.js

+43-43
Original file line numberDiff line numberDiff line change
@@ -1054,8 +1054,8 @@ var inputType = {
10541054
* Since the element value should always reflect the current model value, a range input
10551055
* will set the bound ngModel expression to the value that the browser has set for the
10561056
* input element. For example, in the following input `<input type="range" ng-model="model.value">`,
1057-
* if I set `model.value = null`, the browser will set the input to `'50'`. Angular will then set
1058-
* the model to `50`, to prevent input and model value being out of sync.
1057+
* if the application sets `model.value = null`, the browser will set the input to `'50'`.
1058+
* Angular will then set the model to `50`, to prevent input and model value being out of sync.
10591059
*
10601060
* This does not only affect changes to the model value, but also to the values of the `min` and
10611061
* `max` attributes. When these change in a way that will cause the browser to modify the input value,
@@ -1076,7 +1076,7 @@ var inputType = {
10761076
* adds no native HTML5 validation. It also means the browser won't adjust the
10771077
* element value in case `min` is greater than the current value.
10781078
* @param {string=} ngMax Takes an expression. Sets the `max` validation to ensure that the value
1079-
* entered is less than `max`. Does not set the `min` attribute and therefore
1079+
* entered is less than `max`. Does not set the `max` attribute and therefore
10801080
* adds no native HTML5 validation. It also means the browser won't adjust the
10811081
* element value in case `max` is less than the current value.
10821082
* @param {string=} ngChange Angular expression to be executed when the ngModel value changes due
@@ -1085,25 +1085,24 @@ var inputType = {
10851085
* @example
10861086
<example name="range-input-directive" module="rangeExample">
10871087
<file name="index.html">
1088-
<script>
1089-
angular.module('rangeExample', [])
1090-
.controller('ExampleController', ['$scope', function($scope) {
1091-
$scope.value = 75;
1092-
$scope.min = 10;
1093-
$scope.max = 90;
1094-
}]);
1095-
</script>
1096-
<form name="myForm" ng-controller="ExampleController">
1097-
1098-
Model as range: <input type="range" name="range" ng-model="value"
1099-
min="{{min}}" max="{{max}}">
1100-
<hr>
1101-
Model as number: <input type="number" ng-model="value"><br>
1102-
Min: <input type="number" ng-model="min"><br>
1103-
Max: <input type="number" ng-model="min"><br>
1104-
value = <code>{{value}}</code><br/>
1105-
myForm.range.$valid = <code>{{myForm.range.$valid}}</code><br/>
1106-
myForm.range.$error = <code>{{myForm.range.$error}}</code>
1088+
<script>
1089+
angular.module('rangeExample', [])
1090+
.controller('ExampleController', ['$scope', function($scope) {
1091+
$scope.value = 75;
1092+
$scope.min = 10;
1093+
$scope.max = 90;
1094+
}]);
1095+
</script>
1096+
<form name="myForm" ng-controller="ExampleController">
1097+
1098+
Model as range: <input type="range" name="range" ng-model="value" min="{{min}}" max="{{max}}">
1099+
<hr>
1100+
Model as number: <input type="number" ng-model="value"><br>
1101+
Min: <input type="number" ng-model="min"><br>
1102+
Max: <input type="number" ng-model="min"><br>
1103+
value = <code>{{value}}</code><br/>
1104+
myForm.range.$valid = <code>{{myForm.range.$valid}}</code><br/>
1105+
myForm.range.$error = <code>{{myForm.range.$error}}</code>
11071106
</form>
11081107
</file>
11091108
</example>
@@ -1113,24 +1112,23 @@ var inputType = {
11131112
* @example
11141113
<example name="range-input-directive-ng" module="rangeExample">
11151114
<file name="index.html">
1116-
<script>
1117-
angular.module('rangeExample', [])
1118-
.controller('ExampleController', ['$scope', function($scope) {
1119-
$scope.value = 75;
1120-
$scope.min = 10;
1121-
$scope.max = 90;
1122-
}]);
1123-
</script>
1124-
<form name="myForm" ng-controller="ExampleController">
1125-
Model as range: <input type="range" name="range" ng-model="value"
1126-
ng-min="10" ng-max="90">
1127-
<hr>
1128-
Model as number: <input type="number" ng-model="value"><br>
1129-
Min: <input type="number" ng-model="min"><br>
1130-
Max: <input type="number" ng-model="min"><br>
1131-
value = <code>{{value}}</code><br/>
1132-
myForm.range.$valid = <code>{{myForm.range.$valid}}</code><br/>
1133-
myForm.range.$error = <code>{{myForm.range.$error}}</code>
1115+
<script>
1116+
angular.module('rangeExample', [])
1117+
.controller('ExampleController', ['$scope', function($scope) {
1118+
$scope.value = 75;
1119+
$scope.min = 10;
1120+
$scope.max = 90;
1121+
}]);
1122+
</script>
1123+
<form name="myForm" ng-controller="ExampleController">
1124+
Model as range: <input type="range" name="range" ng-model="value" ng-min="min" ng-max="max">
1125+
<hr>
1126+
Model as number: <input type="number" ng-model="value"><br>
1127+
Min: <input type="number" ng-model="min"><br>
1128+
Max: <input type="number" ng-model="min"><br>
1129+
value = <code>{{value}}</code><br/>
1130+
myForm.range.$valid = <code>{{myForm.range.$valid}}</code><br/>
1131+
myForm.range.$error = <code>{{myForm.range.$error}}</code>
11341132
</form>
11351133
</file>
11361134
</example>
@@ -1594,15 +1592,16 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
15941592
// IE11 doesn't set the el val correctly if the minVal is greater than the element value
15951593
if (minVal > elVal) {
15961594
element.val(minVal);
1595+
elVal = minVal;
15971596
}
1598-
ctrl.$setViewValue(element.val());
1597+
ctrl.$setViewValue(elVal);
15991598
} else {
16001599
// TODO(matsko): implement validateLater to reduce number of validations
16011600
ctrl.$validate();
16021601
}
16031602
}
16041603

1605-
var minAttrType = isDefined(attr.min) ? 'min' : attr.ngMin ? 'ngMin' : false;
1604+
var minAttrType = isDefined(attr.ngMin) ? 'ngMin' : isDefined(attr.min) ? 'min' : false;
16061605
if (minAttrType) {
16071606
ctrl.$validators.min = isDefined(attr.min) && supportsRange ?
16081607
function noopMinValidator(value) {
@@ -1634,8 +1633,9 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
16341633
// IE11 doesn't set the el val correctly if the maxVal is less than the element value
16351634
if (maxVal < elVal) {
16361635
element.val(maxVal);
1636+
elVal = minVal;
16371637
}
1638-
ctrl.$setViewValue(element.val());
1638+
ctrl.$setViewValue(elVal);
16391639
} else {
16401640
// TODO(matsko): implement validateLater to reduce number of validations
16411641
ctrl.$validate();

test/ng/directive/inputSpec.js

+13-19
Original file line numberDiff line numberDiff line change
@@ -2829,23 +2829,19 @@ describe('input', function() {
28292829
scope = $rootScope;
28302830
});
28312831

2832-
it('should parse the input value to a Number', function() {
2833-
var inputElm = helper.compileInput('<input type="range" ng-model="age" />');
2834-
2835-
helper.changeInputValueTo('75');
2836-
expect(scope.age).toBe(75);
2837-
});
2838-
28392832
if (supportsRange) {
28402833
// This behavior only applies to browsers that implement the range input, which do not
28412834
// allow to set a non-number value and will set the value of the input to 50 even when you
28422835
// change it directly on the element.
28432836
// Other browsers fall back to text inputs, where setting a model value of 50 does not make
2844-
// sense if the input value is a string. These browser will mark the input as invalid instead.
2837+
// sense if the input value is a string. These browsers will mark the input as invalid instead.
28452838

28462839
it('should render as 50 if null', function() {
28472840
var inputElm = helper.compileInput('<input type="range" ng-model="age" />');
28482841

2842+
helper.changeInputValueTo('25');
2843+
expect(scope.age).toBe(25);
2844+
28492845
scope.$apply('age = null');
28502846

28512847
expect(inputElm.val()).toEqual('50');
@@ -2887,6 +2883,14 @@ describe('input', function() {
28872883
});
28882884
}
28892885

2886+
it('should parse the input value to a Number', function() {
2887+
var inputElm = helper.compileInput('<input type="range" ng-model="age" />');
2888+
2889+
helper.changeInputValueTo('75');
2890+
expect(scope.age).toBe(75);
2891+
});
2892+
2893+
28902894
it('should only invalidate the model if suffering from bad input when the data is parsed', function() {
28912895
scope.age = 60;
28922896

@@ -2904,21 +2908,11 @@ describe('input', function() {
29042908
});
29052909

29062910

2907-
it('should validate with undefined viewValue when $validate() called', function() {
2908-
var inputElm = helper.compileInput('<input type="range" name="alias" ng-model="value" />');
2909-
2910-
scope.form.alias.$validate();
2911-
2912-
expect(inputElm).toBeValid();
2913-
expect(scope.form.alias.$error.number).toBeUndefined();
2914-
});
2915-
2916-
29172911
it('should throw if the model value is not a number', function() {
29182912
expect(function() {
29192913
scope.value = 'one';
29202914
var inputElm = helper.compileInput('<input type="range" ng-model="value" />');
2921-
}).toThrowMinErr('ngModel', 'numfmt', "Expected `one` to be a number");
2915+
}).toThrowMinErr('ngModel', 'numfmt', 'Expected `one` to be a number');
29222916
});
29232917

29242918

0 commit comments

Comments
 (0)