ion-input with type "number" conflicts with maxlength attribute
See original GitHub issueShort 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:
- Add ion-input with type ‘number’ and set maxlength=“10”
- Enter more than 10 numbers
<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
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Ionic-3 ion-input maxlength attribute not working
According to this post: maxlength ignored for input type="number" in Chrome. Maxlength doesn't work on input type="number".
Read more >Where is maxLength on ion-input? - Ionic Forum
When I debug and deploy to Android device I can enter unlimited characters in the ion-input. it's like the maxlength attribute is ignored...
Read more >Ionic Framework - Ionic Forum
<ion-input text-center autofocus="true" type="number" ... But i see that autofocus & maxlength & minlength have no effect Image may be NSFW.
Read more >HTMLTextAreaElement - Web APIs | MDN
maxLength, long: Returns / Sets the element's maxlength attribute, indicating the maximum number of characters the user can enter.
Read more >ion-input decimal
Store the number as inputted, and format using the decimal pipe when ... of the problem: ion-input with type "number" conflicts with maxlength...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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>
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!