-
Notifications
You must be signed in to change notification settings - Fork 27.4k
ng-option doesn't handle first selection properly under IE11 #7692
Comments
What I'm seeing is: The model value IS actually being set correctly, HOWEVER For the first selection, the incorrect option appears to be selected in the view. But for subsequent selections, it seems to work as expected This is reproducible Seems to be a regression introduced in v1.3.0-beta.3 (http://plnkr.co/edit/jCt2PBLmwmAzStgjJa69?p=preview), probably by f40f54c / dc149de |
This also affects IE10 and IE9 |
Angular Works fine with Angular |
Yeah. Do you have access to a native windows machine @TimotheeJeannin? If you do, do you want to try to work on a fix for this? I can try later in the week, but I don't have a native windows machine, so it's a bit trickier for me, and I'll be a bit occupied. We should definitely fix this asap. |
I do have access to a native windows machine and may be able to work on a fix. |
fantastic --- if you need help I can pair with you on getting it working, just let me know |
Hi @caitp, I have the following test case that passes on Chrome and Firefox and fails on IE: it('should display the selected element while handling initially undefined model', function() {
scope.fields = [
{ name: "zero", id: 0 },
{ name: "one", id: 1 },
{ name: "two", id: 2 }
];
compile('<select ng-model="fieldId" ' +
'ng-options="field.id as field.name for field in fields">' +
'</select>');
// Select the option { name: "two", id: 2 }
// It's index is 3 as an empty option has been automatically added to handle the undefined fieldId model
browserTrigger(element.find('option').eq(3));
expect(element).toEqualSelect('0', '1', ['2']);
}); I'm digging through the select.js source code but I can't find where IE is not behaving properly. I reverted this commit f40f54c and the test case continues to fail on IE but if I do a How do you think we should solve this ? |
It might not be an issue that is easy to test, unfortunately. @wesleycho did you ever figure out a way to test this behaviour synchronously? |
I used an existing app to work with this behavior (although ultimately failed at fixing the issue) - it is a hard thing to reproduce, and I failed at attempting to reproduce it as well. |
An issue has been reported for Microsoft for further investigation. You can track the status here: |
I was able to reproduce this without Angular in IE11 in this small example: http://plnkr.co/edit/Fh91IY3yCj3beRJ2atYN?p=preview ^^^ If you open that in IE11 and select the second option, it will incorrectly show "first". Also, I found a workaround that seems to be working for me: http://plnkr.co/edit/hlvhL0UHVJC3wgDAVFO0?p=preview Not saying this is a solution, but might help anyone looking for a workaround. |
IE9, IE10 and IE11 would always show the first <option> as selected when the user moves from a null <option> to a non-null one in a non-null <select>. Even though the model was being updated correctly, visually, the first <option> always appeared selected. Setting the `selected` property twice in a row seems to fix it in all the three versions mentioned above. Closes angular#7692
Okay --- so what we have is basically 3 different issues (at least, I might be missing some).
So, I think we've been mixing up these issues a fair bit over the course of dealing with them, f40f54c (and the 1.2 port) don't seem to be responsible for all of these issues, but I'm still leaning towards reverting it anyway and getting 2. fixed in Gecko. We still have the issue with IE, and we still have the difference of behaviour between FF and chrome when dynamically inserting options |
IE9, IE10 and IE11 would always show the first <option> as selected when the user moves from a null <option> to a non-null one in a non-null <select>. Even though the model was being updated correctly, visually, the first <option> always appeared selected. Setting the `selected` property twice in a row seems to fix it in all the three versions mentioned above. Closes #7692 Closes #8158
IE9, IE10 and IE11 would always show the first <option> as selected when the user moves from a null <option> to a non-null one in a non-null <select>. Even though the model was being updated correctly, visually, the first <option> always appeared selected. Setting the `selected` property twice in a row seems to fix it in all the three versions mentioned above. Closes angular#7692 Closes angular#8158
Found a workaround for IE. I am setting the selection value($scope.fieldId = 1;) in the controller here is the plunkr: http://plnkr.co/edit/RXv6gUJkh4wzZ3AvmMne?p=preview |
Yh ..m also facing the same issue. Is there any fix for this? |
just tried @gz7 solution but doesn't fit my case... would prefer to have nothing selected. Any fix for this? |
Providing some form of default option, either in the controller or via the one allowed empty value option tag, seems to handle the situation. This option can have the value (display or actual) of <select ng-model="modelName" ng-options="label for (key, value) in object">
<option value="">
</option>
</select> Sadly, this does keep a blank value available on the dropdown. I'm using separate validation to ensure that this blank option is not considered valid. It may be necesssary to manually initialize the DOM dropdown's selectedIndex property to -1. Will experiment when I get the chance. |
@ttydaeus Thanks. I add the 'required' tag to the select element and then prevent form submission if there are form errors. It's not the correct fix, but will do for the short term. Note: I'm using Angular 1.3.16 and this is still a bug in IE10. However the bug doesn't appear in IE11. |
I'm seeing this issue in Google Chrome Version 47.0.2498.0 dev-m (64-bit) with Angular 1.2.27. |
Has this been resolved or not? As I am still having this issue and had to temp fix it by having empty option tag.Using it with angularjs 1.2.16 |
I have a multiple select. The issue comes up when there is only one option returns from data retrieval. I am not sure this relates to this issue but wants to get some idea. |
@dannycsng The changelog marks this as fixed in 1.2.21: c0afbfa |
Selecting an option for the first time in a select dropdown under IE11 when no option is currently selected
Reproducible: alaways
Browsers: IE11
Operating system: Windows 7, Windows 8
Steps to reproduce:
second
,third
,fourth
orfifth
optionfirst
instead of the selected optionor
-- choose color --
in the dropdown next toColor (null allowed):
red
in the dropdown next toColor (null not allowed):
black
instead ofred
The text was updated successfully, but these errors were encountered: