I have a TableView in with rows containing controls. I'd like to be able to disable / enable all the child controls for individual rows. However when I set the enabled property of TextFields (not sure about other controls just yet) it does not seem to be honored, I can still interact with the TextField control.
Here's my code for looking through the children in the TableViewRow:
for (var c in row.children) { Ti.API.info('BEFORE :: row.children[c]: ' + row.children[c].toString() + '; enabled: ' + row.children[c].enabled); if (typeof row.children[c].enabled !== 'undefined') row.children[c].enabled = isEnabled; Ti.API.info('AFTER :: row.children[c]: ' + row.children[c].toString() + '; enabled: ' + row.children[c].enabled); }And here is the Ti.API.info output:
[INFO] BEFORE :: row.children[c]: [object TiUILabel]; enabled: undefined [INFO] AFTER :: row.children[c]: [object TiUILabel]; enabled: undefined [INFO] BEFORE :: row.children[c]: [object TiUITextField]; enabled: true [INFO] AFTER :: row.children[c]: [object TiUITextField]; enabled: falseAny idea why the TextField is remaining enabled afterwards?
2 Answers
It turns out that the enabled property is ignored in controls like TextField if you call .focus(). Once .focus() is called the user is able to interact with the control regardless.
In my case I had added a click event to the parent row so the user could click anywhere in the row and the TextField would get the focus for editing. This is why disabling controls wasn't working for me. I now set an _enabled property on the row and check this before calling focus().
You should probably add the controls which you want to toggle ealnable to an separate Array, like
var row = ...; ... row._controls = ...;its possible SDK Bug but before we Claim that TRY a clean build.
Your Answer
Think you can help? Login to answer this question!