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

Commit b28bfdb

Browse files
committed
try to make clearer, and remove unused code
1 parent 90034fd commit b28bfdb

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

src/ng/directive/input.js

+12-19
Original file line numberDiff line numberDiff line change
@@ -1567,10 +1567,8 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
15671567

15681568
if (minAttrType) {
15691569
ctrl.$validators.min = minAttrType === 'min' && supportsRange ?
1570-
function noopMinValidator() {
1571-
// Since all browsers set the input to a valid value, we don't need to check validity
1572-
return true;
1573-
} :
1570+
// Since all browsers set the input to a valid value, we don't need to check validity
1571+
function noopMinValidator() { return true; } :
15741572
// ngMin doesn't set the min attr, so the browser doesn't adjust the input value as setting min would
15751573
function minValidator(modelValue, viewValue) {
15761574
return ctrl.$isEmpty(viewValue) || isUndefined(minVal) || viewValue >= minVal;
@@ -1581,10 +1579,8 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
15811579

15821580
if (maxAttrType) {
15831581
ctrl.$validators.max = maxAttrType === 'max' && supportsRange ?
1584-
function noopMaxValidator() {
1585-
// Since all browsers set the input to a valid value, we don't need to check validity
1586-
return true;
1587-
} :
1582+
// Since all browsers set the input to a valid value, we don't need to check validity
1583+
function noopMaxValidator() { return true; } :
15881584
// ngMax doesn't set the max attr, so the browser doesn't adjust the input value as setting max would
15891585
function maxValidator(modelValue, viewValue) {
15901586
return ctrl.$isEmpty(viewValue) || isUndefined(maxVal) || viewValue <= maxVal;
@@ -1593,19 +1589,16 @@ function rangeInputType(scope, element, attr, ctrl, $sniffer, $browser) {
15931589
setInitialValueAndObserver(maxAttrType, 'max', maxChange);
15941590
}
15951591

1596-
function setInitialValueAndObserver(attrType, attrName, changeFn) {
1597-
var initialAttrValue;
1598-
if (attrType === attrName) {
1599-
initialAttrValue = attr[attrName];
1600-
// Set the actual element attribute so that the browser can adjust the value based on
1601-
// the max value, which might be interpolated
1602-
element.attr(attrName, initialAttrValue);
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]);
16031599
}
16041600

1605-
// This initalizes the min/max value, so that non-support browsers validate with the correct
1606-
// values during the initial $render
1607-
changeFn(initialAttrValue);
1608-
attr.$observe(attrName, changeFn);
1601+
attr.$observe(htmlAttrName, changeFn);
16091602
}
16101603

16111604
function minChange(val) {

test/ng/directive/inputSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3108,7 +3108,7 @@ describe('input', function() {
31083108
describe('ngMin', function() {
31093109

31103110
it('should validate', function() {
3111-
var inputElm = helper.compileInput('<input type="range" ng-model="value" name="alias" ng-min="20" />');
3111+
var inputElm = helper.compileInput('<input type="range" ng-model="value" name="alias" ng-min="50" />');
31123112

31133113
helper.changeInputValueTo('1');
31143114
expect(inputElm).toBeInvalid();

0 commit comments

Comments
 (0)