Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for pass formControl into the suffix/prefix material template #2895

Closed
wizardnet972 opened this issue Jun 21, 2021 · 1 comment · Fixed by #3023
Closed

add support for pass formControl into the suffix/prefix material template #2895

wizardnet972 opened this issue Jun 21, 2021 · 1 comment · Fixed by #3023

Comments

@wizardnet972
Copy link

wizardnet972 commented Jun 21, 2021

Is your feature request related to a problem? Please describe.
form-field in material doesn't support passing params into the suffix/prefix template. at least it should pass the formControl.

Why? Because sometimes the select can have suffix with an action. not just display template. for example to clear the value of the formControl.

Consider this code:

<mat-form-field>
  <mat-select formControlName="team" placeholder="Team">
    <mat-option *ngFor="let team of availableTeams" [value]="team.id">
      {{team.name}}
    </mat-option>
  </mat-select>
  <button
    *ngIf="form.controls.team.value"
    matSuffix
    mat-icon-button
    type="button"
    aria-label="Clear"
    (click)="form.controls.team.setValue(null); $event.stopPropagation()">
    <mat-icon>close</mat-icon>
  </button>
</mat-form-field>

It's simple select and the button should display only when the value exists. and if so you can clear the value (x).

Describe the solution you'd like
The solution is can be very simple, just add ngTemplateOutletContext or any similar directive to pass the formControl into the template.

Additional context

Need simple change here: https://github.com/ngx-formly/ngx-formly/blob/main/src/ui/material/form-field/src/form-field.wrapper.ts#L68.

I can send a PR if you want.

@aitboudad
Copy link
Member

I can send a PR if you want.

yes please, passing field would be enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants