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

Commit 105858e

Browse files
committed
fix(inputs): ignoring input events in IE caused by placeholder changes or focus/blur on inputs with placeholders
1 parent b9e899c commit 105858e

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/ng/directive/input.js

+24-7
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,6 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
915915

916916
function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
917917
var validity = element.prop(VALIDITY_STATE_PROPERTY);
918-
var placeholder = element[0].placeholder, noevent = {};
919918
var type = lowercase(element[0].type);
920919

921920
// In composition mode, users are still inputing intermediate text buffer,
@@ -934,17 +933,35 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
934933
});
935934
}
936935

936+
// IE (11 and under) seem to emit an 'input' event if the placeholder value changes or when
937+
// an input with a placeholder gains or loses focus. These issues do not happen if the input
938+
// has a value at the time.
939+
if (msie && ('placeholder' in element[0]) && $sniffer.hasEvent('input')) {
940+
var ignoreNextInput;
941+
942+
// Changing placeholders triggers an input if there is no value
943+
var oldPlaceholder;
944+
attr.$observe("placeholder", function ieIgnoreNextInputPlaceholder(newPlaceholder) {
945+
ignoreNextInput = (newPlaceholder !== oldPlaceholder) && !element[0].value;
946+
oldPlaceholder = newPlaceholder;
947+
});
948+
949+
// Focus in/out triggers an input if there is no value but there is a placeholder
950+
// Event orders:
951+
// focus: focusin focus input
952+
// blur: focusout input blur
953+
element.on("focusin focusout", function ieIgnoreNextInputFocus() {
954+
ignoreNextInput = this.placeholder && !this.value;
955+
});
956+
}
957+
937958
var listener = function(ev) {
938959
if (composing) return;
939960
var value = element.val(),
940961
event = ev && ev.type;
941962

942-
// IE (11 and under) seem to emit an 'input' event if the placeholder value changes.
943-
// We don't want to dirty the value when this happens, so we abort here. Unfortunately,
944-
// IE also sends input events for other non-input-related things, (such as focusing on a
945-
// form control), so this change is not entirely enough to solve this.
946-
if (msie && (ev || noevent).type === 'input' && element[0].placeholder !== placeholder) {
947-
placeholder = element[0].placeholder;
963+
if (ignoreNextInput && event === 'input') {
964+
ignoreNextInput = false;
948965
return;
949966
}
950967

0 commit comments

Comments
 (0)