Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Select control, reactiveforms and display value #2058

@gpulido

Description

@gpulido

Is your feature request related to a problem? Please describe.
I have a reactive form with one control that has to be filled with an object of a type Club:

interface Club{
  name: string;
  url: string;
}

I create a list of clubs, and fill the select with it:

<div fxLayout="row" fxLayoutGap="10px" fxLayout="row" fxLayoutGap="10px grid">
        <mdc-select formControlName="club" label="Club" [helperText]="clubHelper" [outlined]="true" [floatLabel]="true" fxFlex="76%">
          <mdc-menu>
            <mdc-list [avatar]="true">
              <mdc-list-item *ngFor="let club of clubs" [value]="club">
                <img mdcListItemGraphic [src]="club.imageUrl" />{{ club.name }}
              </mdc-list-item>
            </mdc-list>
          </mdc-menu>
        </mdc-select>
        <mdc-select-helper-text #clubHelper [validation]="true">
          <span *ngIf="form.controls['club'].hasError('required')">Club is required</span>
        </mdc-select-helper-text>
        <div fxFlex="10%">
          <img
            *ngIf="form.controls.club.value"
            mdcSelectIcon
            [src]="form.controls.club.value.imageUrl"
            class="proportional-image"
          />
        </div>
      </div>

The problem is that when I select a club from the picker, the formcontrol property is filled property but the selector placeholder is being shown as empty as it doens't know how to represent a "Club".

Describe the solution you'd like
To be able to tell the mdc-select wich property of the binded object should use to represent it without needed to change the formControlName property value

Describe alternatives you've considered
To create two forms properties: club and clubName, and use formControlName = "clubName", and every time an item is selected traverse the list of clubs to find the one with the name and fill the club property of the form manually.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions