@@ -475,7 +475,6 @@ function addNativeHtml5Validators(ctrl, validatorName, badFlags, ignoreFlags, va
475
475
476
476
function textInputType ( scope , element , attr , ctrl , $sniffer , $browser ) {
477
477
var validity = element . prop ( VALIDITY_STATE_PROPERTY ) ;
478
- var placeholder = element [ 0 ] . placeholder , noevent = { } ;
479
478
ctrl . $$validityState = validity ;
480
479
481
480
// In composition mode, users are still inputing intermediate text buffer,
@@ -494,18 +493,33 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
494
493
} ) ;
495
494
}
496
495
496
+ // IE (11 and under) seem to emit an 'input' event if the placeholder value changes or when
497
+ // an input with a placeholder gains or loses focus. These issues do not happen if the input
498
+ // has a value at the time.
499
+ if ( msie && ( 'placeholder' in element [ 0 ] ) && $sniffer . hasEvent ( 'input' ) ) {
500
+ var ignoreNextInput ;
501
+
502
+ // Changing placeholders triggers an input if there is no value
503
+ attr . $observe ( "placeholder" , function ieIgnoreNextInputPlaceholder ( ) {
504
+ ignoreNextInput = ! element [ 0 ] . value ;
505
+ } ) ;
506
+
507
+ // Focus in/out triggers an input if there is no value but there is a placeholder
508
+ // Event orders:
509
+ // focus: focusin focus input
510
+ // blur: focusout input blur
511
+ element . on ( "focusin focusout" , function ieIgnoreNextInputFocus ( ) {
512
+ ignoreNextInput = this . placeholder && ! this . value ;
513
+ } ) ;
514
+ }
515
+
497
516
var listener = function ( ev ) {
498
517
if ( composing ) return ;
499
- var value = element . val ( ) ;
500
-
501
- // IE (11 and under) seem to emit an 'input' event if the placeholder value changes.
502
- // We don't want to dirty the value when this happens, so we abort here. Unfortunately,
503
- // IE also sends input events for other non-input-related things, (such as focusing on a
504
- // form control), so this change is not entirely enough to solve this.
505
- if ( msie && ( ev || noevent ) . type === 'input' && element [ 0 ] . placeholder !== placeholder ) {
506
- placeholder = element [ 0 ] . placeholder ;
518
+ if ( ignoreNextInput && ev && ev . type === 'input' ) {
519
+ ignoreNextInput = false ;
507
520
return ;
508
521
}
522
+ var value = element . val ( ) ;
509
523
510
524
// By default we will trim the value
511
525
// If the attribute ng-trim exists we will avoid trimming
0 commit comments