How can I validate the data when it is edited or introduced? In the events (createConfirm)
/ (editConfirm)
I could validate them, but I also want to show the validation message in a label for each text box.
Hi, if you want to show label on form go through the below code.
.ts
import { FormGroup, FormControl, Validators } from '@angular/forms';
MTDeviceSetupFormControl = new FormControl('', [
Validators.required,
]);
.html
<div class="form-group">
<label class="control-label" for="name">Name *</label>
<div class="col-sm-9">
<input type="text" maxlength="15" class="form-control" required name="Name" [(ngModel)]="name.emp_name">
</div>
</div>
<label [hidden]="name.emp_name">Enter Name</label>
If you want to use inside table after edit go through this code:
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header> Name </mat-header-cell>
<mat-cell *matCellDef="let row">
<span *ngIf="row_id != row.emp_id">{{row.emp_name}}</span>
<form>
<mat-form-field *ngIf="row_id == row.emp_id" floatPlaceholder="never">
<input matInput maxlength="15" required [formControl]="EmpFormControl" placeholder="Name" [value]="name.emp_name"
[(ngModel)]="name.emp_name">
<mat-error *ngIf="EmpFormControl.hasError('required')">
<span *ngIf="!name.emp_name">
<label>Name Required</label>
</span>
</mat-error>
</mat-form-field>
</form>
</mat-cell>
</ng-container>