K
K
Konstantin2020-09-24 11:47:45
Angular
Konstantin, 2020-09-24 11:47:45

How to validate all Angular form fields?

I am using template driven form:

<form #documentForm="ngForm" autocomplete="off">
     <mat-form-field>
                    <mat-label>{{ fieldDefinition.title }}</mat-label>
                    <input
                        matInput
                        type="text"
                        name="{{ elementName }}"
                        #ref="ngModel"
                        [required]="fieldDefinition.isrequired"
                        [pattern]="fieldDefinition.mask"
                        [(ngModel)]="fieldDefinition.value"
                    />

                    <mat-error *ngIf="ref.touched && ref.invalid">
                        {{ fieldDefinition.maskdef }}
                    </mat-error>
                </mat-form-field>
</form>


How to validate all fields on button click and show tooltips for required and pattern if fields are invalid?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question