Skip to content

Commit 47569cb

Browse files
committed
fix(ngModel): use paste/cut events in IE to support context menu
In IE the model is not updated when the input value is modified using the context menu, e.g. pasting from the clipboard, or cutting all or part of the current value. To capture these changes, we bind to the proprietary 'paste' and 'cut' events. Closes angular#1462
1 parent 23abb99 commit 47569cb

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/ng/directive/input.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -413,23 +413,32 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
413413
} else {
414414
var timeout;
415415

416+
var deferListener = function() {
417+
if (!timeout) {
418+
timeout = $browser.defer(function() {
419+
listener();
420+
timeout = null;
421+
});
422+
}
423+
};
424+
416425
element.bind('keydown', function(event) {
417426
var key = event.keyCode;
418427

419428
// ignore
420429
// command modifiers arrows
421430
if (key === 91 || (15 < key && key < 19) || (37 <= key && key <= 40)) return;
422431

423-
if (!timeout) {
424-
timeout = $browser.defer(function() {
425-
listener();
426-
timeout = null;
427-
});
428-
}
432+
deferListener();
429433
});
430434

431435
// if user paste into input using mouse, we need "change" event to catch it
432436
element.bind('change', listener);
437+
438+
// if user modifies input value using context menu in IE, we need "paste" and "cut" events to catch it
439+
if ($sniffer.hasEvent('paste')) {
440+
element.bind('paste cut', deferListener);
441+
}
433442
}
434443

435444

0 commit comments

Comments
 (0)