Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
/angular.jsPublic archive

Commit6273af0

Browse files
committed
fix(input): update $viewValue when cleared
- Fix when user clicks clear button in an input element in IE, $viewValue not being correctly updated
1 parent9686f3a commit6273af0

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

‎src/ng/directive/input.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,11 +1103,11 @@ function stringBasedInputType(ctrl) {
11031103
}
11041104

11051105
functiontextInputType(scope,element,attr,ctrl,$sniffer,$browser){
1106-
baseInputType(scope,element,attr,ctrl,$sniffer,$browser);
1106+
baseInputType(scope,element,attr,ctrl,$sniffer,$browser,'text');
11071107
stringBasedInputType(ctrl);
11081108
}
11091109

1110-
functionbaseInputType(scope,element,attr,ctrl,$sniffer,$browser){
1110+
functionbaseInputType(scope,element,attr,ctrl,$sniffer,$browser,inputType){
11111111
vartype=lowercase(element[0].type);
11121112

11131113
// In composition mode, users are still inputing intermediate text buffer,
@@ -1126,7 +1126,11 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
11261126
});
11271127
}
11281128

1129-
vartimeout;
1129+
vartimeout,oldVal;
1130+
varviewValueUpdated=true,msieInput=msie>=10&&msie<=11;
1131+
if(msieInput&&inputType==='text'){
1132+
oldVal=element.val();
1133+
}
11301134

11311135
varlistener=function(ev){
11321136
if(timeout){
@@ -1152,10 +1156,18 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
11521156
}
11531157
};
11541158

1159+
functionieListener(ev){
1160+
varval=element.val();
1161+
if(val===oldVal&&!viewValueUpdated)return;
1162+
oldVal=val;
1163+
viewValueUpdated=isDefined(ctrl.$modelValue);
1164+
listener(ev);
1165+
}
1166+
11551167
// if the browser does support "input" event, we are fine - except on IE9 which doesn't fire the
11561168
// input event on backspace, delete or cut
11571169
if($sniffer.hasEvent('input')){
1158-
element.on('input',listener);
1170+
element.on('input',msie ?ieListener :listener);
11591171
}else{
11601172
vardeferListener=function(ev,input,origValue){
11611173
if(!timeout){
@@ -1212,6 +1224,10 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
12121224
// Workaround for Firefox validation #12102.
12131225
varvalue=ctrl.$isEmpty(ctrl.$viewValue) ?'' :ctrl.$viewValue;
12141226
if(element.val()!==value){
1227+
// Workaround for IE 10 & 11 input updates #11193
1228+
if(msieInput){
1229+
viewValueUpdated=true;
1230+
}
12151231
element.val(value);
12161232
}
12171233
};

‎src/ng/sniffer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function $SnifferProvider() {
7373
// when cut operation is performed.
7474
// IE10+ implements 'input' event but it erroneously fires under various situations,
7575
// e.g. when placeholder changes, or a form is focused.
76-
if(event==='input'&&msie<=11)returnfalse;
76+
if(event==='input'&&msie<=9)returnfalse;
7777

7878
if(isUndefined(eventSupport[event])){
7979
vardivElm=document.createElement('div');

‎test/ng/snifferSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('$sniffer', function() {
135135
// IE10+ implementation is fubared when mixed with placeholders
136136
mockDivElement={oninput:noop};
137137

138-
expect($sniffer.hasEvent('input')).toBe(!(msie&&msie<=11));
138+
expect($sniffer.hasEvent('input')).toBe(!(msie&&msie<=9));
139139
});
140140
});
141141

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp