2

I'm using Angular Material input fields and there is a problem that fields become red as soon as user does something to it.

However, I need these fields to stay "valid" until the form is submitted, so that the user starts seeing errors only after clicking submit button.

In casual inputs I've used that thing <input [class.ng-invalid]="control.invalid && submitted"> thus it starts turning red after clicking "Submit".

However that didn't help me when I tried to apply this to matInput

<mat-form-field class="w-100">
    <input [id]="id" matInput
           [class.ng-invalid]="control.errors && submitted"
           [placeholder]="getPlaceholder()"
           [formControl]="control">
</mat-form-field>

How do I achieve displaying errors only after submitting?

1 Answer 1

3

Solved by creating own ErrorStateMatch as described in https://material.angular.io/components/input/overview#changing-when-error-messages-are-shown

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.