Browse Source

feat(client): migrate to form control

pull/5364/head
KenTandrian 1 week ago
committed by Thomas Kaul
parent
commit
74e69cec85
  1. 10
      apps/client/src/app/core/notification/prompt-dialog/prompt-dialog.component.ts
  2. 9
      apps/client/src/app/core/notification/prompt-dialog/prompt-dialog.html

10
apps/client/src/app/core/notification/prompt-dialog/prompt-dialog.component.ts

@ -1,5 +1,5 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms'; import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule, MatDialogRef } from '@angular/material/dialog'; import { MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { MatFormFieldModule } from '@angular/material/form-field'; import { MatFormFieldModule } from '@angular/material/form-field';
@ -7,11 +7,11 @@ import { MatInputModule } from '@angular/material/input';
@Component({ @Component({
imports: [ imports: [
FormsModule,
MatButtonModule, MatButtonModule,
MatDialogModule, MatDialogModule,
MatFormFieldModule, MatFormFieldModule,
MatInputModule MatInputModule,
ReactiveFormsModule
], ],
selector: 'gf-prompt-dialog', selector: 'gf-prompt-dialog',
templateUrl: './prompt-dialog.html' templateUrl: './prompt-dialog.html'
@ -20,8 +20,8 @@ export class GfPromptDialogComponent {
public confirmLabel: string; public confirmLabel: string;
public defaultValue: string; public defaultValue: string;
public discardLabel: string; public discardLabel: string;
public formControl = new FormControl('');
public title: string; public title: string;
public value: string;
public valueLabel: string; public valueLabel: string;
public constructor(public dialogRef: MatDialogRef<GfPromptDialogComponent>) {} public constructor(public dialogRef: MatDialogRef<GfPromptDialogComponent>) {}
@ -36,8 +36,8 @@ export class GfPromptDialogComponent {
this.confirmLabel = aParams.confirmLabel; this.confirmLabel = aParams.confirmLabel;
this.defaultValue = aParams.defaultValue; this.defaultValue = aParams.defaultValue;
this.discardLabel = aParams.discardLabel; this.discardLabel = aParams.discardLabel;
this.formControl.setValue(aParams.defaultValue);
this.title = aParams.title; this.title = aParams.title;
this.value = aParams.defaultValue;
this.valueLabel = aParams.valueLabel; this.valueLabel = aParams.valueLabel;
} }
} }

9
apps/client/src/app/core/notification/prompt-dialog/prompt-dialog.html

@ -7,7 +7,7 @@
@if (valueLabel) { @if (valueLabel) {
<mat-label>{{ valueLabel }}</mat-label> <mat-label>{{ valueLabel }}</mat-label>
} }
<input matInput [(ngModel)]="value" /> <input matInput [formControl]="formControl" />
</mat-form-field> </mat-form-field>
</div> </div>
@ -15,7 +15,12 @@
<button mat-button (click)="dialogRef.close('discard')"> <button mat-button (click)="dialogRef.close('discard')">
{{ discardLabel }} {{ discardLabel }}
</button> </button>
<button color="primary" mat-flat-button (click)="dialogRef.close(value)"> <button
color="primary"
mat-flat-button
[disabled]="!formControl.dirty"
(click)="dialogRef.close(formControl.value)"
>
{{ confirmLabel }} {{ confirmLabel }}
</button> </button>
</div> </div>

Loading…
Cancel
Save