#form - mark

10 messages · Page 1 of 1 (latest)

golden pewter
#
        <mat-form-field>
            <mat-label>Code</mat-label>
            <input matInput formControlName="code" placeholder="Code" type="text" [readonly]="editMode"/>
            <mat-error *ngIf="checkErrorForm('code', 'required')">Le code est obligatoire</mat-error>
            <mat-error *ngIf="checkErrorForm('code', 'maxlength')">Le nombre de caractères est limité à 1</mat-error>
        </mat-form-field>
...
...
form = this._formBuilder.group({
    equipe:     ['', [Validators.required,  ],  ],
    code:       ['', [Validators.required, Validators.maxLength(1),]],

the default operation is that when I enter characters even if I enter 5 characters, the error does not occur.
the error only appears when I leave the field.
I would like that when you enter 2 characters, the error is immediately displayed.
I have about ten fields as well.

What is the solution ?

soft drift
#

Are you sure you didn't set updateOn: 'blur' somewhere for that FormGroup or specific FormControl.

mint nimbus
frigid stump
soft drift
frigid stump
mint nimbus
soft drift
#

IMHO, in this specific case they're just offering a more complex solution to a functionality already present in the underlying tech (Forms and ReactiveForms).
It's not even a function, but an interface to be implemented.

#

Even if it should be possible using it in a more funtional way.

mint nimbus
#

Reactive forms just tell when a field is dirty, touched and when a form is submitted. It's up to the developer to add ngIf everywhere in their code to decide when error messages should be displayed.
Material has an opinion about that and chooses to display them when the field is touched or the form submitted: it very much relies on the form to to that, just like our own code would.
I agree that the matcher could simply be a function though.