Ionic-3 ion-input maxlength attribute not working
HTML:
<ion-textarea [(ngModel)]=“text” (ionChange)="textareaMaxLengthValidation()"></ion-textarea>
<ion-input type="text" [(ngModel)]=“text” (ionChange)="textareaMaxLengthValidation()"></ion-input>
TS:
textareaMaxLengthValidation() {
if (text.length > 50) {
text= text.slice(0, 50);
}
According to this post: maxlength ignored for input type="number" in Chrome
Maxlength doesn't work on input type="number"
One alternative is suggested here: https://github.com/ionic-team/ionic/issues/7072 where dilhan119 suggests using type="tel"
A robust solution is to use a form validator, which will prevent form submission (and can show the user an error): https://www.joshmorony.com/advanced-forms-validation-in-ionic-2/