Skip to content

Select field in Safari displays option but does not set value when default value is null  #14505

Closed as not planned

Description

@janaleible

I'm submitting a ... (check one with "x")

[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

Activity

  1. stieler-it commented on Aug 10, 2017

    @stieler-it

    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

    setTimeout(() => {
      this.offices = ['Office1'];
    }, 1000);
    

    and using let officeOptions of offices | async makes 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.

  2. janaleible commented on Aug 10, 2017

    @janaleible
    Author

    There's a template-only workaround which has so far worked quite well for me:

    <form [formGroup]="form">
    	<select formControlName="select">
    		<option *ngIf="!form.value.select" [ngValue]="null" selected disabled></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.)

  3. stieler-it commented on Aug 10, 2017

    @stieler-it

    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.

  4. janaleible commented on Aug 10, 2017

    @janaleible
    Author

    Seems to be an issue with template driven forms. This is a working solution using a model driven approach.

  5. stieler-it commented on Aug 10, 2017

    @stieler-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!

  6. slawojstanislawski commented on Sep 15, 2017

    @slawojstanislawski

    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.

  7. added this to the Backlog milestone on Jan 24, 2018
  8. bappy004 commented on Feb 8, 2018

    @bappy004

    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).

  9. theodorejb commented on May 4, 2018

    @theodorejb
    Contributor

    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

  10. theodorejb commented on May 7, 2018

    @theodorejb
    Contributor

    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.

  11. theodorejb commented on May 9, 2018

    @theodorejb
    Contributor

    I created pull request #23784 to fix this.

  12. 24 remaining items

  13. removed
    P3
    on Oct 1, 2020
  14. modified the milestones: Backlog, needsTriage on Oct 1, 2020
  15. added
    P4
    on Oct 1, 2020
  16. modified the milestones: needsTriage, Backlog on Oct 1, 2020
  17. AlecRobertson commented on May 27, 2021

    @AlecRobertson

    Come across this myself, it is insane this has not been merged.

  18. 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
  19. atscott commented on Jun 13, 2024

    @atscott
    Contributor

    This looks to no longer be an issue in the latest version of safari. Closing.

  20. angular-automatic-lock-bot commented on Jul 14, 2024

    @angular-automatic-lock-bot

    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.

  21. locked and limited conversation to collaborators on Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4area: formsbrowser: safarifreq2: mediumstate: confirmedtype: bug/fix

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions