Skip to content

ion-select should re-evaluate .text when list options updated #15788

Closed

Description

@webprofusion-chrisc

Bug Report

Ionic:

   ionic (Ionic CLI)          : 4.1.2 (/usr/local/lib/node_modules/ionic)
   Ionic Framework            : @ionic/angular 4.0.0-beta.12
   @angular-devkit/core       : 0.7.2
   @angular-devkit/schematics : 0.7.2
   @angular/cli               : 6.1.5
   @ionic/ng-toolkit          : 1.0.7
   @ionic/schematics-angular  : 1.0.5

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 7.1.1, browser 5.0.4, ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 2.0.2, (and 7 other plugins)

System:

   Android SDK Tools : 26.1.1 (/Users/chrisc/Library/Android/sdk)
   ios-deploy        : 2.0.0
   ios-sim           : 7.0.0
   NodeJS            : v8.11.3 (/usr/local/bin/node)
   npm               : 6.4.1
   OS                : macOS High Sierra
   Xcode             : Xcode 10.0 Build version 10A255

Describe the Bug
If an ion-select has ion-select-options (ngFor) bound to an array which is then updated async, the select options update OK but the selected value shown in the UI is not. This is because ion-select only sets this.text when this.valueChanged fires, not when the related ion-select-options children are refreshed.

https://github.com/ionic-team/ionic/blob/master/core/src/components/select/select.tsx#L123

Workaround:
Binding [selectedText] to the required selected value works:

<ion-select [(ngModel)]="offer.growerNumber" name="growerNumber" okText="OK" cancelText="Dismiss" placeholder="Choose..." [selectedText]="offer.growerNumber">
            <ion-select-option *ngFor="let i of growerNumbers" [value]="i">{{i}}</ion-select-option>
          </ion-select>

Expected Behavior
When data source for ion-select-option list resolves via async call, the selected value should be shown in the UI.

Additional Context
https://forum.ionicframework.com/t/ionic-4-ion-select-and-change-detection/141643/2

Activity

  1. paulstelzer commented on Dec 7, 2018

    @paulstelzer
    Contributor

    Thanks for your issue! Could you please check if this is still an issue in beta.17? That would be very nice :)

  2. added
    needs: reply
    on Dec 7, 2018
  3. denisroldan commented on Dec 11, 2018

    @denisroldan

    @paulstelzer Experiencing the same issue here. The values doesn't appear until you tap on them and they magically appear.

    
    Ionic:
    
       ionic (Ionic CLI)             : 4.5.0 (/usr/local/lib/node_modules/ionic)
       Ionic Framework               : @ionic/angular 4.0.0-beta.17
       @angular-devkit/build-angular : 0.10.7
       @angular-devkit/schematics    : 7.0.7
       @angular/cli                  : 7.0.7
       @ionic/angular-toolkit        : not installed
    
    System:
    
       NodeJS : v10.11.0 (/usr/local/bin/node)
       npm    : 6.4.1
       OS     : macOS Mojave
    
  4. added and removed
    needs: reply
    on Dec 11, 2018
  5. denisroldan commented on Dec 14, 2018

    @denisroldan

    @paulstelzer It magically works now. Sorry! 😅 From my side, it just works as expected on Ionic 4 latest ;)

  6. paulstelzer commented on Dec 14, 2018

    @paulstelzer
    Contributor

    @webprofusion-chrisc Could you check if your issue is also solved when updating to beta.18?

  7. added
    needs: reply
    and removed
    package: core
    on Dec 14, 2018
  8. 2 remaining items

  9. webprofusion-chrisc commented on Dec 15, 2018

    @webprofusion-chrisc
    Author

    Note as an aside that I started the test case using ionic start myApp tabs --type=angular which serves up a version that's 2 releases old and has broken tabs once you upgrade, so this is a new one hosted in the sidemenu template on beta 19.

    Really the test here is populating the list in an async way (as you would if loading from a service), then setting the bound selected value.

    The displayed selected value only becomes 'three' after you start interacting with the list, which is possibly an angular change detection thing, however the 'status' text (also updated async) displays immediately.

  10. sneko commented on Jan 17, 2019

    @sneko

    I think I have the exact same issue. I use something like:

                  ion-select(... :selectedText="selectedElement.id")
                    ion-select-option(v-for='element in elements' :value='element.id') {{ element.id + ' ' + element.name }}
    

    But the selectedText I can see when the select is closed is equal to element.id + ' ' + element.name instead of just selectedElement.id

    Is it still an issue on your side?

    Note that it was working with an old Angular+Ionic2 project
    Note2: the syntax is due to Vue.js ;)

    EDIT: I tried to fix a value without binding it to JS code with selectedText="justATest" but it doesn't override the preview in the select

  11. self-assigned this
    on Mar 29, 2019
  12. nomanshahsyed commented on Jun 26, 2019

    @nomanshahsyed

    Hi, has anyone found the solution to this problem? I have the exact same problem. I have different pages and they share a same array. When some of the page POPs or SPLICEs an entry then the select options are not updated in the UI. Although they seem to be changed in the console.

    Another tricky thing is that the select options are updated on one page but not on the other one. The difference in these pages is that the one where teh options are not updated, the ion-select is wrapped around a DIV.

  13. added a commit that references this issue on Aug 27, 2019
    48a2763
  14. added a commit that references this issue on Aug 27, 2019
    7eb1089
  15. added a commit that references this issue on Aug 27, 2019
    69ee964
  16. liamdebeasi commented on Sep 4, 2019

    @liamdebeasi
    Contributor

    A fix for this is available in Ionic 4.9.0. For any new bugs, please create a new issue.

    Thanks!

  17. ionitron-bot commented on Oct 4, 2019

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  18. locked and limited conversation to collaborators on Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

package: core

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions