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

Commit c9d4df0

Browse files
committed
fixup: call the listener directly instead of triggering an input event
1 parent a0ceb82 commit c9d4df0

File tree

2 files changed

+48
-63
lines changed

2 files changed

+48
-63
lines changed

src/ng/directive/input.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,9 +1141,9 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
11411141
// without an accompanying change in the input value (thus no `input` event).
11421142
// (This is only necessary on browsers that support inputs of that type - other browsers set the
11431143
// `type` property to "text".)
1144-
var isTypeSupported = (type === attr.type);
1145-
var listenForKeyup = isTypeSupported && (DATE_INPUT_TYPES.indexOf(type) !== -1);
1146-
if (listenForKeyup) element.on('keyup', function() { element.triggerHandler('input'); });
1144+
var browserSupportsType = (type === attr.type);
1145+
var listenForKeyup = browserSupportsType && (DATE_INPUT_TYPES.indexOf(type) !== -1);
1146+
if (listenForKeyup) element.on('keyup', function() { listener('input'); });
11471147
} else {
11481148
var timeout;
11491149

test/ng/directive/inputSpec.js

Lines changed: 45 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -707,21 +707,18 @@ describe('input', function() {
707707
});
708708

709709

710-
it('should fire \'input\' event on \'keyup\' only on browsers that support this input type',
711-
function() {
712-
var inputType = 'month';
713-
714-
var inputEventExpectedToFire = browserSupportsInputTypeAndEvent(inputType, 'input');
715-
var inputEventActuallyFired = false;
710+
it('should listen for \'keyup\' only on browsers that support this input type', function() {
711+
var inputType = 'month';
716712

717-
var inputElm = helper.compileInput('<input type="' + inputType + '" ng-model="val" />');
718-
inputElm.on('input', function() { inputEventActuallyFired = true; });
713+
var inputElm = helper.compileInput('<input type="' + inputType + '" ng-model="val" />');
714+
var expandoStore = jqLiteExpandoStore(inputElm[0]);
715+
var events = expandoStore && expandoStore.events;
719716

720-
browserTrigger(inputElm, 'keyup');
717+
var keyupListenerExpectedToBePresent = browserSupportsInputTypeAndEvent(inputType, 'input');
718+
var keyupListenerActuallyPresent = !!(events && events.keyup);
721719

722-
expect(inputEventActuallyFired).toBe(inputEventExpectedToFire);
723-
}
724-
);
720+
expect(keyupListenerActuallyPresent).toBe(keyupListenerExpectedToBePresent);
721+
});
725722

726723

727724
describe('min', function() {
@@ -989,21 +986,18 @@ describe('input', function() {
989986
});
990987

991988

992-
it('should fire \'input\' event on \'keyup\' only on browsers that support this input type',
993-
function() {
994-
var inputType = 'week';
989+
it('should listen for \'keyup\' only on browsers that support this input type', function() {
990+
var inputType = 'week';
995991

996-
var inputEventExpectedToFire = browserSupportsInputTypeAndEvent(inputType, 'input');
997-
var inputEventActuallyFired = false;
992+
var inputElm = helper.compileInput('<input type="' + inputType + '" ng-model="val" />');
993+
var expandoStore = jqLiteExpandoStore(inputElm[0]);
994+
var events = expandoStore && expandoStore.events;
998995

999-
var inputElm = helper.compileInput('<input type="' + inputType + '" ng-model="val" />');
1000-
inputElm.on('input', function() { inputEventActuallyFired = true; });
996+
var keyupListenerExpectedToBePresent = browserSupportsInputTypeAndEvent(inputType, 'input');
997+
var keyupListenerActuallyPresent = !!(events && events.keyup);
1001998

1002-
browserTrigger(inputElm, 'keyup');
1003-
1004-
expect(inputEventActuallyFired).toBe(inputEventExpectedToFire);
1005-
}
1006-
);
999+
expect(keyupListenerActuallyPresent).toBe(keyupListenerExpectedToBePresent);
1000+
});
10071001

10081002

10091003
describe('min', function() {
@@ -1306,21 +1300,18 @@ describe('input', function() {
13061300
});
13071301

13081302

1309-
it('should fire \'input\' event on \'keyup\' only on browsers that support this input type',
1310-
function() {
1311-
var inputType = 'datetime-local';
1312-
1313-
var inputEventExpectedToFire = browserSupportsInputTypeAndEvent(inputType, 'input');
1314-
var inputEventActuallyFired = false;
1303+
it('should listen for \'keyup\' only on browsers that support this input type', function() {
1304+
var inputType = 'datetime-local';
13151305

1316-
var inputElm = helper.compileInput('<input type="' + inputType + '" ng-model="val" />');
1317-
inputElm.on('input', function() { inputEventActuallyFired = true; });
1306+
var inputElm = helper.compileInput('<input type="' + inputType + '" ng-model="val" />');
1307+
var expandoStore = jqLiteExpandoStore(inputElm[0]);
1308+
var events = expandoStore && expandoStore.events;
13181309

1319-
browserTrigger(inputElm, 'keyup');
1310+
var keyupListenerExpectedToBePresent = browserSupportsInputTypeAndEvent(inputType, 'input');
1311+
var keyupListenerActuallyPresent = !!(events && events.keyup);
13201312

1321-
expect(inputEventActuallyFired).toBe(inputEventExpectedToFire);
1322-
}
1323-
);
1313+
expect(keyupListenerActuallyPresent).toBe(keyupListenerExpectedToBePresent);
1314+
});
13241315

13251316

13261317
describe('min', function() {
@@ -1699,21 +1690,18 @@ describe('input', function() {
16991690
});
17001691

17011692

1702-
it('should fire \'input\' event on \'keyup\' only on browsers that support this input type',
1703-
function() {
1704-
var inputType = 'time';
1705-
1706-
var inputEventExpectedToFire = browserSupportsInputTypeAndEvent(inputType, 'input');
1707-
var inputEventActuallyFired = false;
1693+
it('should listen for \'keyup\' only on browsers that support this input type', function() {
1694+
var inputType = 'time';
17081695

1709-
var inputElm = helper.compileInput('<input type="' + inputType + '" ng-model="val" />');
1710-
inputElm.on('input', function() { inputEventActuallyFired = true; });
1696+
var inputElm = helper.compileInput('<input type="' + inputType + '" ng-model="val" />');
1697+
var expandoStore = jqLiteExpandoStore(inputElm[0]);
1698+
var events = expandoStore && expandoStore.events;
17111699

1712-
browserTrigger(inputElm, 'keyup');
1700+
var keyupListenerExpectedToBePresent = browserSupportsInputTypeAndEvent(inputType, 'input');
1701+
var keyupListenerActuallyPresent = !!(events && events.keyup);
17131702

1714-
expect(inputEventActuallyFired).toBe(inputEventExpectedToFire);
1715-
}
1716-
);
1703+
expect(keyupListenerActuallyPresent).toBe(keyupListenerExpectedToBePresent);
1704+
});
17171705

17181706

17191707
describe('min', function() {
@@ -2067,21 +2055,18 @@ describe('input', function() {
20672055
});
20682056

20692057

2070-
it('should fire \'input\' event on \'keyup\' only on browsers that support this input type',
2071-
function() {
2072-
var inputType = 'date';
2073-
2074-
var inputEventExpectedToFire = browserSupportsInputTypeAndEvent(inputType, 'input');
2075-
var inputEventActuallyFired = false;
2058+
it('should listen for \'keyup\' only on browsers that support this input type', function() {
2059+
var inputType = 'date';
20762060

2077-
var inputElm = helper.compileInput('<input type="' + inputType + '" ng-model="val" />');
2078-
inputElm.on('input', function() { inputEventActuallyFired = true; });
2061+
var inputElm = helper.compileInput('<input type="' + inputType + '" ng-model="val" />');
2062+
var expandoStore = jqLiteExpandoStore(inputElm[0]);
2063+
var events = expandoStore && expandoStore.events;
20792064

2080-
browserTrigger(inputElm, 'keyup');
2065+
var keyupListenerExpectedToBePresent = browserSupportsInputTypeAndEvent(inputType, 'input');
2066+
var keyupListenerActuallyPresent = !!(events && events.keyup);
20812067

2082-
expect(inputEventActuallyFired).toBe(inputEventExpectedToFire);
2083-
}
2084-
);
2068+
expect(keyupListenerActuallyPresent).toBe(keyupListenerExpectedToBePresent);
2069+
});
20852070

20862071

20872072
describe('min', function() {

0 commit comments

Comments
 (0)