[TIMOB-5810] Android: maxLength propery on TextField and TextArea
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-07-30T18:14:20.000+0000 |
Affected Version/s | Release 2.1.0 |
Fix Version/s | Sprint 2012-16 API, Release 3.0.0 |
Components | Android |
Labels | api, module_textarea, parity, qe-testadded |
Reporter | Sindre Sorhus |
Assignee | Hieu Pham |
Created | 2011-10-19T11:22:18.000+0000 |
Updated | 2012-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.
Feature request to limit the number of characters allowed in a text field.
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