You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Select field in Safari displays option but does not set value when default value is null #14505
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
This happens with the Internet Explorer and older versions of Firefox (does happen in version 40, does not happen in version 50): When no default value (or explicitly null) is set for a select field's form control, the first option is displayed in the UI but not set as value in the corresponding FormControl.
Side note: Manually selecting the already displayed value does not set the FormControl's value either. To select this option one must first select a different option and then the first one again, only then the value property is correctly set.
Expected behavior
I'd expect the field to be empty initially. If this cannot be done, I'd at least expect the FormControl's value property to be set correctly (reflecting the displayed value).
Minimal reproduction of the problem with instructions
Create a select field with no default value and view in IE/older Firefox. Minimal example
Please tell us about your environment:
Tested on Windows 7 and 10 using Chrome 56 and Firefox 50 (behave as expected) and Internet Explorer 11 and Firefox 40 (buggy)
Angular version: 2.4.7
Language: TypeScript 2.0.2
Reacted by Alexander, Russell Hoy, Mitchell Barry, Theodore Brown, David Aschliman, Ethan-G, systemasis, Krzysztof Karol, Dennis Ameling, Dominik Nguyen and 11 more
This problem does still exist with Angular v4.3.3. It is actually worse if the select box contains only one element. The option looks like selected, although it isn't (in the model). If the select is required, it is not possible to get the form into valid state.
I have made another Plunker that shows how to reproduce it in template based forms. Please note that the problem occurs only if the option values are set delayed. So both
There's a template-only workaround which has so far worked quite well for me:
<form[formGroup]="form"><selectformControlName="select"><option*ngIf="!form.value.select" [ngValue]="null" selecteddisabled></option><option*ngFor="let option of options" [ngValue]="option">{{option}}</option></select></form>
This will display a blank option while no value is set, which disappears as soon as another value is selected. (You may have to use "form.value.select === null" if your select has valid options that evaluate to false.)
Reacted by Michael Cornel, Daniel Shin, slawojstanislawski, Nizamul Morshed, Andrej Bartko, Jerold Sumner, Mohannd Lababidy, PamProg, Matt Hernandez, Di Wang and 8 more
Unfortunately, IE is still not happy. In my updated Plunker, IE shows two options but still the first "real" option is shown as selected and it is not possible to make a selection. Removing the "disabled" attribute seems to fix it.
Yes, the model driven version works in my IE 11 as well. Although this is currently not an option for us, the workaround without "disabled" should already be fine for our application. Thanks for the hints!
In my project on angular 4.3.1 the solution from #14505 (comment) works for a dynamic form - I also had to remove the disabled attribute (as mentioned in the previous comment) for it to work on IE 11.
I'm using a reactive form and I too had to remove the disabled attribute from the solution (#14505 (comment)) to make it work for edge (angular 5.2.2).
It looks like @DzmitryShylovich had a branch for fixing this, but it hasn't been touched for over a year. Is there anything I can do to help move this forward? Our app has a bunch of forms that are broken in IE 11 because of this bug. @kara
changed the title [-]Select field in IE displays option but does not set value when default value is null [/-][+]Select field in Safari displays option but does not set value when default value is null [/+]on Mar 21, 2022
Activity
stieler-it commentedon Aug 10, 2017
This problem does still exist with Angular v4.3.3. It is actually worse if the select box contains only one element. The option looks like selected, although it isn't (in the model). If the select is required, it is not possible to get the form into valid state.
I have made another Plunker that shows how to reproduce it in template based forms. Please note that the problem occurs only if the option values are set delayed. So both
and using
let officeOptions of offices | asyncmakes IE11 show the unselected item as selected.This is interesting as the example of @janaleible does set the option values immediately and the bug still shows up.
janaleible commentedon Aug 10, 2017
There's a template-only workaround which has so far worked quite well for me:
This will display a blank option while no value is set, which disappears as soon as another value is selected. (You may have to use
"form.value.select === null"if your select has valid options that evaluate tofalse.)stieler-it commentedon Aug 10, 2017
Unfortunately, IE is still not happy. In my updated Plunker, IE shows two options but still the first "real" option is shown as selected and it is not possible to make a selection. Removing the "disabled" attribute seems to fix it.
janaleible commentedon Aug 10, 2017
Seems to be an issue with template driven forms. This is a working solution using a model driven approach.
stieler-it commentedon Aug 10, 2017
Yes, the model driven version works in my IE 11 as well. Although this is currently not an option for us, the workaround without "disabled" should already be fine for our application. Thanks for the hints!
slawojstanislawski commentedon Sep 15, 2017
In my project on angular 4.3.1 the solution from #14505 (comment) works for a dynamic form - I also had to remove the disabled attribute (as mentioned in the previous comment) for it to work on IE 11.
bappy004 commentedon Feb 8, 2018
I'm using a reactive form and I too had to remove the disabled attribute from the solution (#14505 (comment)) to make it work for edge (angular 5.2.2).
theodorejb commentedon May 4, 2018
It looks like @DzmitryShylovich had a branch for fixing this, but it hasn't been touched for over a year. Is there anything I can do to help move this forward? Our app has a bunch of forms that are broken in IE 11 because of this bug. @kara
theodorejb commentedon May 7, 2018
Here's a minimal reproduction of the issue: https://angular-select-ie-bug.stackblitz.io.
A form value can be selected as expected in Chrome, Firefox, and Edge, but not Safari or IE 11.
theodorejb commentedon May 9, 2018
I created pull request #23784 to fix this.
24 remaining items
AlecRobertson commentedon May 27, 2021
Come across this myself, it is insane this has not been merged.
[-]Select field in IE displays option but does not set value when default value is null [/-][+]Select field in Safari displays option but does not set value when default value is null [/+]atscott commentedon Jun 13, 2024
This looks to no longer be an issue in the latest version of safari. Closing.
angular-automatic-lock-bot commentedon Jul 14, 2024
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.