Bug
when the user enters invalid number , mat-error message should appear
mat-error not showing
I tried with min and minlength but nothing is working
<mat-form-field>
<input type="number" min="0" matInput name="totCarton" [(ngModel)]="container.totalCarton">
<mat-error>{{'error.min'|translate:param}}</mat-error>
</mat-form-field>
or
<mat-form-field class="full-width">
<input #totCarton="ngModel" matInput type="number" min="0" placeholder="{{'tot.carton'|translate}}" name="totCarton" [(ngModel)]="container.totalCarton">
<mat-error *ngIf="totCarton.hasError('min')">{{'error.min'|translate:param}}</mat-error>
</mat-form-field>
angular 4.4.6
material 2.0.0-beta.12
typescript 2.3.4
all browsers
If I understand correctly what you want:
According to the MDN documentation on minlength:
If the value of the type attribute is
text,search,password,tel, orurl, this attribute specifies the minimum number of characters (in Unicode code points) that the user can enter. For other control types, it is ignored.
With min (MDN documentation) it will work, but it's only related to the _value_.
The minimum (numeric or date-time) value for this item, which must not be greater than its maximum (max attribute) value.
This StackBlitz example will get you in the right direction. You only need to add a custom validator that only allows digits to be entered.
For future questions:
Please keep GitHub issues for bug reports / feature requests. Better avenues for troubleshooting / questions are stack overflow, gitter, mailing list, etc.
Seems like an issue with angular forms. Here's an example demonstrating that it doesn't work even without Material: https://stackblitz.com/edit/angular-q2fhul-vyu9iz?file=app/form-field-error-example.ts
Maybe related to this: https://github.com/angular/angular/issues/17080
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
Seems like an issue with angular forms. Here's an example demonstrating that it doesn't work even without Material: https://stackblitz.com/edit/angular-q2fhul-vyu9iz?file=app/form-field-error-example.ts
Maybe related to this: https://github.com/angular/angular/issues/17080