Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5810] Android: maxLength propery on TextField and TextArea

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-07-30T18:14:20.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sSprint 2012-16 API, Release 3.0.0
ComponentsAndroid
Labelsapi, module_textarea, parity, qe-testadded
ReporterSindre Sorhus
AssigneeHieu Pham
Created2011-10-19T11:22:18.000+0000
Updated2012-09-07T14:05:09.000+0000

Description

TextField and TextArea needs a property to control the max length of the input text. Though this can be done using an eventlistener and a length check. It would be very useful if this was built-in.
var win = Ti.UI.createWindow();

var txt = Ti.UI.createTextField({
    top: 150,
	height: 100,
    backgroundColor: "white"
});

/* var txt = Ti.UI.createTextArea({
    top: 150,
    height: 100,
    backgroundColor: "white" */

var button = Ti.UI.createButton( {
    title: "set max length to 10"
});

button.addEventListener('click', function(e) {
   txt.maxLength = 10;
});
Ti.API.info("maxLength: " + txt.maxLength);
win.add(txt);
win.add(button);
win.open();
1. Run code 2. Check log, make sure maxLength is -1 3. Click on button 4. Start typing, the content should not exceed 10 characters. 5. Re-run code, this time enter 20+ characters before click on button 6. Click on button, text now should truncate to 10 characters 7. Repeat 1-6 on textArea.

Comments

  1. Kevin Whinnery 2011-10-20

    Feature request to limit the number of characters allowed in a text field.
  2. Rima Umbrasas 2012-08-13

    Verified fixed with mobile sdk-2.2.0.v20120810080115 Titanium Studio, build: 2.1.1.201207271312 Device: Galaxy S III Android version 4.0.4

JSON Source