Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13364] Android: TextArea maxLength not working in Android

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2014-10-02T21:00:33.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterCarter Lathrop
AssigneeSunila
Created2013-04-03T17:19:52.000+0000
Updated2017-03-16T22:29:30.000+0000

Description

According to the docs, TextArea supports maxLength property from SDK 3.0. However, maxLength does not work in Android. In TiUIText.java, the code that reads the maxLength is: if (d.containsKey(TiC.PROPERTY_MAX_LENGTH) && field) { maxLength = TiConvert.toInt(d, TiC.PROPERTY_MAX_LENGTH); } TextArea has "field" boolean set to false, so maxLength is always ignored. Steps to reproduce. Create simple App.js:
var win = Ti.UI.createWindow({
  backgroundColor: 'white'
});
var textArea = Ti.UI.createTextArea({
  borderWidth: 2,
  borderColor: '#bbb',
  borderRadius: 5,
  color: '#888',
  textAlign: 'left',  
  maxLength: 10,
  top: 60,
  width: 300,
  height : 150
});
win.add(textArea);
win.open();
Launch app and start writing in the text area. You can enter more than 10 chars, despite maxLength is set to 10. Tested with SDK 3.0.0.GA in Android 2.3.3 and Android 4.1

Comments

  1. Carter Lathrop 2013-04-03

    Javier, Would you please post a simple test case that shows this bug? Providing a test case for issues allows for a much quicker and smoother review and turnaround time. Once a valid test case is provided we can continue to process the bug. For reference: https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report Thank you for your assistance, Carter
  2. javier ferrero 2013-04-04

    Added test case. Regards
  3. Carter Lathrop 2013-04-04

    Tested and confirmed, maxLength is not working atm. Moved to Ti-Mobile. Carter
  4. Anand T 2013-04-18

    Issue reproduced in 3.1.0GA also
  5. François Mériaux 2014-08-15

    The issue is still going on with 3.3.0 GA. It is really an annoying problem for all the apps that allow to write tweets. I guess a solution would be to remove the condition on "field" in TiUIText.java : turn
       if (d.containsKey(TiC.PROPERTY_MAX_LENGTH) && field) {
           maxLength = TiConvert.toInt(d.get(TiC.PROPERTY_MAX_LENGTH), -1);
       }
       
    into
       if (d.containsKey(TiC.PROPERTY_MAX_LENGTH)) {
           maxLength = TiConvert.toInt(d.get(TiC.PROPERTY_MAX_LENGTH), -1);
       }
       
  6. Sunila 2014-09-28

    Remove the check for textfield ('field') when setting maxLength as this is available to textArea also https://github.com/appcelerator/titanium_mobile/pull/6178
  7. sagar k patel 2014-12-10

    HI Ingo, I am facing the in MaxLength property in TextArea in android, And i am using 3.4.1.GA SDK . Issue is still open in android. So pls give some suggestion or solution so make it work for android
  8. Lee Morris 2017-03-16

    Closing ticket as fixed.

JSON Source