Skip to content

bug: v7, cannot pass dynamic label to form controls #27085

Closed

Description

@judsonmusic

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

Upgraded to IONIC 7 RC a couple of day ago. I got all of the warnings about the ion label being deprected and needing to replace with label="something" labelPlacement="stacked" etc...

I have a reusable component in which i am passing the label via attribute like so:
<app-frequency-select controlName="medfrequency" label="When will this be taken?" [required]="true"></app-frequency-select>

Inside the component you see i'm trying to pass an input to customize the value of the select.
HTML:

<ion-item>
  <ion-select
    required
    [label]="label"
    labelPlacement="stacked"
    #frequencySelect
    [formControlName]="controlName"
    placeholder="Please Select"
  >
    <ion-select-option [value]="f.frequencyid" *ngFor="let f of frequencies">{{ f.frequency }}</ion-select-option>
  </ion-select>
</ion-item>

component.ts:

@Component({
  selector: 'app-frequency-select',
  standalone: true,
  templateUrl: './frequency-select.component.html',
  styleUrls: ['./frequency-select.component.scss'],
  imports: [CommonModule, IonicModule, FormsModule, ReactiveFormsModule, RequiredDirective, SelectLabelFixDirective],
  viewProviders: [
    {
      provide: ControlContainer,
      useFactory: (container: ControlContainer) => container,
      deps: [[new SkipSelf(), ControlContainer]]
    }
  ]
})
export class FrequencySelectComponent {
  @ViewChild('frequencySelect') fs: IonSelect;
  @Input() label: string;
  @Input() required: boolean = false;
  @Input() controlName: string;
  frequencies: any[] = [];
  disabled: boolean;

  constructor(private _referenceService: ReferenceService) {}

  async ngOnInit() {
    await this.buildReferences();
    console.log('The label for FS:', this.label); //this is coming through just fine..
  }
  async buildReferences() {
    const t = setTimeout(async () => {
      this.frequencies = await lastValueFrom(this._referenceService.getFrequencies());
      clearTimeout(t);
    }, 1000);
  }
}

As you can see in my comment the label comes through just fine but when i try to render it into [label]="label"
it does not work. No label gets rendered.

I am forced for the time being to put static text like label="something" which works.

Expected Behavior

I should be able to pass a string to the label in my reusable component and the [label] attribute render the text that I have sent as an @input() label;

Steps to Reproduce

Create and input and try passing dynamic text to the label with brackets like so
<ion-input [label]="somevariableforlabel"></ion-input>

in the component file:

public somevariableforlabel = 'My label';

Code Reproduction URL

No response

Ionic Info

Ionic:

Ionic CLI : 7.0.0 (/Users/abcd/.nvm/versions/node/v16.18.0/lib/node_modules/@ionic/cli)
Ionic Framework : not installed
@angular-devkit/build-angular : 15.2.4
@angular-devkit/schematics : 15.2.4
@angular/cli : 15.2.4
@ionic/angular-toolkit : 6.1.0

Capacitor:

Capacitor CLI : 4.6.1
@capacitor/android : 4.6.1
@capacitor/core : 4.6.1
@capacitor/ios : 4.6.1

Utility:

cordova-res : 0.15.4
native-run (update available: 1.7.2) : 1.7.1

System:

NodeJS : v16.18.0 (/Users/abcd/.nvm/versions/node/v16.18.0/bin/node)
npm : 9.6.2
OS : macOS Unknown

Additional Information

Let me know if you need anymore information. Thank you.

Activity

  1. changed the title [-]bug: [/-] [+]bug: Cannot pass dynamic label to ion-input[/+] on Apr 2, 2023
  2. judsonmusic commented on Apr 2, 2023

    @judsonmusic
    Author

    I have created a stackblitz to show the issue on both parent and child:
    https://stackblitz.com/edit/ionic7-label-test?file=src/app/app.component.ts
    Notice initially it might work with dynamic label but change some label text in the ts files and it breaks.
    Also despite having the correct [label] attr. getting this in the console:
    image
    However you can see my code is correct:
    image

    If i refresh the page they seem to work, but they do not work in my application when entering into new views etc.

  3. self-assigned this
    on Apr 3, 2023
  4. added
    package: core
    type: bug
    on Apr 3, 2023
  5. removed their assignment
    on Apr 3, 2023
  6. JustinPierce commented on Apr 3, 2023

    @JustinPierce

    I would add that I have noticed this behavior with any Ionic component that I've tried to set a dynamic label on, and not just <ion-input>. All of our labels are run through an i18n package, so dynamic labels are non-negotiable for us.

  7. muuvmuuv commented on Apr 4, 2023

    @muuvmuuv

    Also noticed that the shadow-root changes on navigation/re-hydration. Our label just prints fine but when navigating its gone. And we do not use the [legacy]="true" attr.

    SCR-20230404-kfxn
    SCR-20230404-kfyy

  8. changed the title [-]bug: Cannot pass dynamic label to ion-input[/-] [+]bug: v7, cannot pass dynamic label to form controls[/+] on Apr 10, 2023
  9. Julien-Marcou commented on Apr 10, 2023

    @Julien-Marcou

    I made a reproduction repository which demonstrates the bug when using transloco to translate input labels inside a modal:
    https://github.com/Julien-Marcou/ionic-issue-27085

    The first time the modal opens:

    Screenshot 2023-04-10 at 18-32-58 Ionic App

    And the second time the modal opens:

    Screenshot 2023-04-10 at 18-33-08 Ionic App

  10. Julien-Marcou commented on Apr 10, 2023

    @Julien-Marcou

    Btw, I just found another problem after the second modal opening 😅

    The <ion-input> "focus" state is not the same (there is a colored underline that is not present after the initial opening):

    Record.2023-04-10.184247.mp4
  11. sean-perkins commented on Apr 10, 2023

    @sean-perkins
    Contributor

    Hello everyone, thanks for the reproductions and conversation around this issue.

    Can someone test with this dev-build and let me know if the problem persists or if new issues are observed:

    7.0.2-dev.11681149441.1ec983b5
    

    For example, installing for an Angular project:

    npm install @ionic/[email protected]
    

    Thanks!

  12. Julien-Marcou commented on Apr 10, 2023

    @Julien-Marcou

    I can confirm it fixes the problem for me 🚀

  13. sean-perkins commented on Apr 10, 2023

    @sean-perkins
    Contributor

    Thank you!

    Here is the latest/most up-to-date dev-build:

    7.0.2-dev.11681157690.1060bc7f
    

    I still need to get a team review, but the end result changes here is that we are trying to default to the modern syntax instead of the legacy syntax.

    Developers can still get the legacy UI by either doing:

    <ion-item>
      <ion-label>Label</ion-label>
      <ion-input></ion-input>
    </ion-item>

    or by assigning the legacy="true" property on the control directly:

    <ion-item>
      <ion-input legacy="true"></ion-input>
    </ion-item>

    Implementations that are similar to:

    <ion-item>
      <ion-input></ion-input>
    </ion-item>

    will be force updated to the modern syntax. It is the only discovered way that I can maintain the modern syntax in a scenario where a label is initially unset, but later has a value (translations, shared components, etc.)

  14. ceotrammell commented on Apr 16, 2023

    @ceotrammell

    Thank you!

    Here is the latest/most up-to-date dev-build:

    7.0.2-dev.11681157690.1060bc7f
    

    I still need to get a team review, but the end result changes here is that we are trying to default to the modern syntax instead of the legacy syntax.

    Developers can still get the legacy UI by either doing:

    <ion-item>
      <ion-label>Label</ion-label>
      <ion-input></ion-input>
    </ion-item>
    

    or by assigning the legacy="true" property on the control directly:

    <ion-item>
      <ion-input legacy="true"></ion-input>
    </ion-item>
    

    Implementations that are similar to:

    <ion-item>
      <ion-input></ion-input>
    </ion-item>
    

    will be force updated to the modern syntax. It is the only discovered way that I can maintain the modern syntax in a scenario where a label is initially unset, but later has a value (translations, shared components, etc.)

    Can confirm as well for @ionic/angular that @ionic/angular@^7.0.2-dev.11681157690.1060bc7f fixed this issue!
    Thank you :)

  15. fleboulch commented on Apr 17, 2023

    @fleboulch

    The dev build fixed also the issue for me 🎉

  16. sean-perkins commented on Apr 17, 2023

    @sean-perkins
    Contributor

    The fix for this issue is queued to be merged and will be available in this week's release v7.0.3. Thank you everyone for reporting the issue + helping validate the fix 🎉

  17. added a commit that references this issue on Apr 17, 2023
    30b548b
  18. added a commit that references this issue on Apr 19, 2023
    784e76c
  19. ceotrammell commented on Apr 20, 2023

    @ceotrammell

    Thank you!

    Here is the latest/most up-to-date dev-build:

    7.0.2-dev.11681157690.1060bc7f
    

    I still need to get a team review, but the end result changes here is that we are trying to default to the modern syntax instead of the legacy syntax.

    Developers can still get the legacy UI by either doing:

    <ion-item>
      <ion-label>Label</ion-label>
      <ion-input></ion-input>
    </ion-item>
    

    or by assigning the legacy="true" property on the control directly:

    <ion-item>
      <ion-input legacy="true"></ion-input>
    </ion-item>
    

    Implementations that are similar to:

    <ion-item>
      <ion-input></ion-input>
    </ion-item>
    

    will be force updated to the modern syntax. It is the only discovered way that I can maintain the modern syntax in a scenario where a label is initially unset, but later has a value (translations, shared components, etc.)

    I am unsure if this correlates or not but before I did not have this issue...

    In ionic 6 angular, the below worked:

    <ion-item>
      <ion-label>{{ 'LABEL' | translate }}</ion-label>
      <ion-input></ion-input>
    </ion-item>
    <ion-item>
      <ion-label>{{ 'LABEL2' | translate }}</ion-label>
      <ion-input></ion-input>
    </ion-item>
    

    In ionic 7.0.3 angular, the first 'LABEL' translation does not seem to work, it gives me a warning and does not show the label:

    <ion-item>
      <ion-input label="{{ 'LABEL' | translate }}"></ion-input>
    </ion-item>
    <ion-item>
      <ion-input label="{{ 'LABEL2' | translate }}"></ion-input>
    </ion-item>
    

    I am unsure if this is strictly component related or not but I have seen it mainly happen in components but it is random it seems. I am using '@ngx-translate/core ^14.0.0 via:

    import { TranslateModule } from '@ngx-translate/core';

    The fix for me is to not pipe a translation on the first ion item label and it works and then the rest of the page is fine to allow translation pipes. But this could be annoying for someone who has a wider language base instead of just EN.

    ionic info:

    Ionic:
    
       Ionic CLI                     : 7.0.1 (C:\Users\ME\AppData\Roaming\nvm\v16.17.0\node_modules\@ionic\cli)
       Ionic Framework               : @ionic/angular 7.0.2
       @angular-devkit/build-angular : 15.2.6
       @angular-devkit/schematics    : 15.2.6
       @angular/cli                  : 15.2.6
       @ionic/angular-toolkit        : 8.1.0
    
    Capacitor:
    
       Capacitor CLI      : 4.7.3
       @capacitor/android : 4.7.3
       @capacitor/core    : 4.7.3
       @capacitor/ios     : 4.7.3
    
    Utility:
    
       cordova-res : 0.15.4
       native-run  : 1.7.2
    
    System:
    
       NodeJS : v16.17.0 (C:\Program Files\nodejs\node.exe)
       npm    : 8.15.0
       OS     : Windows 10
    
  20. EinfachHans commented on Apr 20, 2023

    @EinfachHans
    Contributor

    @ceotrammell your ionic info says you have 7.0.2 installed. Make sure to install 7.0.3 correctly than it should work!

  21. ceotrammell commented on Apr 20, 2023

    @ceotrammell

    @EinfachHans GOOD CATCH! I forgot to push my tests to .3 after 7.0.2-dev.11681157690.1060bc7f!
    Silly me. All is back to normal.

  22. ionitron-bot commented on May 20, 2023

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

  23. locked and limited conversation to collaborators on May 20, 2023
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

    package: coretype: bug

    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