Short description of the problem:
ion-input with type "number" conflicts with maxlength attribute, so that the number of characters we input can be more than maxlength. Change type to "tel", everything will be ok.
Steps to reproduce:
<ion-item>
<ion-label>phone</ion-label>
<ion-input type="number" maxlength="10" clearInput [(ngModel)]="userPhone"></ion-input>
</ion-item>
Other information:
Checked on Chrome browsers and on Android 6.0.
Which Ionic Version?
2.0.0-beta.9
Run ionic info from terminal/cmd prompt: (paste output below)
Cordova CLI: 6.2.0
Ionic Framework Version: 2.0.0-beta.9
Ionic CLI Version: 2.0.0-beta.32
Ionic App Lib Version: 2.0.0-beta.18
OS: Mac OS X El Capitan
Node Version: v5.11.1
Hello, thanks for opening an issue with us! The maxlength
attribute is not supported by the number type input. If you would like more info on why and some workarounds feel free to check out this Stack Overflow post. Thanks for using Ionic!
my solution is put input type as a "tel", Because maxlength work with input type as a text & telephone number in ionic 2.
<ion-item>
<ion-label>phone</ion-label>
<ion-input type="tel" maxlength="10" clearInput [(ngModel)]="userPhone"></ion-input>
</ion-item>
@dilhan119 , please, what is the type 'tel'? is it a type you created? If so, how can I create it? I put type tel here and is the same as text I guess...
@GabrielDvt it's one of the new input types introduced in HTML5. It is similar to other newly introduced types such as number
, email
, etc. that you might have used.
<input type="tel" placeholder="Your phone number">
This is an HTML5 built-in type and you don't need anything extra to make use of it.
@dilhan119 but if we use tel in the place of number, even letters are getting accepted. how to get rid of that ?
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.
Most helpful comment
my solution is put input type as a "tel", Because maxlength work with input type as a text & telephone number in ionic 2.
<ion-item>
<ion-label>phone</ion-label>
<ion-input type="tel" maxlength="10" clearInput [(ngModel)]="userPhone"></ion-input>
</ion-item>