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

Commit 0364975

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 0364975

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

Diff for: src/ng/directive/input.js

+22-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,33 @@ 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+
attr.$observe("placeholder", function ieIgnoreNextInputPlaceholder() {
944+
ignoreNextInput = !element[0].value;
945+
});
946+
947+
// Focus in/out triggers an input if there is no value but there is a placeholder
948+
// Event orders:
949+
// focus: focusin focus input
950+
// blur: focusout input blur
951+
element.on("focusin focusout", function ieIgnoreNextInputFocus() {
952+
ignoreNextInput = this.placeholder && !this.value;
953+
});
954+
}
955+
937956
var listener = function(ev) {
938957
if (composing) return;
939958
var value = element.val(),
940959
event = ev && ev.type;
941960

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;
961+
if (ignoreNextInput && event === 'input') {
962+
ignoreNextInput = false;
948963
return;
949964
}
950965

0 commit comments

Comments
 (0)