Need a way to lock textField object for editing

Hey all,

Simple scenario here.  I’ve got a textField and want to lock it’s contents after a button is pressed, so the user can’t edit it anymore (temporarily or permanently).  I was hoping there would be an isEditable or isEnabled property or setEditable or setEnabled methods to do that, but I found none.  Is there a way?

What’s the workaround?

I understand textBox has that property, but I need textField.

Thanks in advance.

I’m not sure if it actually works or not, but newTextBox (rather than newTextField) has an isEditable property:

http://docs.coronalabs.com/api/library/native/newTextBox.html

http://docs.coronalabs.com/api/type/TextBox/index.html

And while looking for that I’ve only just discovered that they both have a “placeholder” property:

http://docs.coronalabs.com/api/type/TextBox/placeholder.html

If I’d known about that I could’ve saved myself lots of time making my own placeholder text objects…

Right.

Like I said, I know textBox has it.  We are talking about textField.

Doh, sorry I didn’t spot that.  

I don’t think that the textfield does have that kind of property, but you could do a table print on a textField object to see if it has any hidden properties? 

Failing that the only (ugly) workaround I can think of is to remove the textfield when you need it “locked”, and replace it with a static rect+text object that looks the same as the textbox.

Hi @sorkinva,

You may also consider storing the “locked” text (whatever that text is) in a string, then when the user attempts to edit the textbox content, simply replace whatever text is in the textbox with the contents of the string. Meaning, if the stored (locked) content is “Hello World.” and the user attempts to type in the box, just replace what they type in the “editing” phase with the stored string.

Brent

1 Like

I’m not sure if it actually works or not, but newTextBox (rather than newTextField) has an isEditable property:

http://docs.coronalabs.com/api/library/native/newTextBox.html

http://docs.coronalabs.com/api/type/TextBox/index.html

And while looking for that I’ve only just discovered that they both have a “placeholder” property:

http://docs.coronalabs.com/api/type/TextBox/placeholder.html

If I’d known about that I could’ve saved myself lots of time making my own placeholder text objects…

Right.

Like I said, I know textBox has it.  We are talking about textField.

Doh, sorry I didn’t spot that.  

I don’t think that the textfield does have that kind of property, but you could do a table print on a textField object to see if it has any hidden properties? 

Failing that the only (ugly) workaround I can think of is to remove the textfield when you need it “locked”, and replace it with a static rect+text object that looks the same as the textbox.

Hi @sorkinva,

You may also consider storing the “locked” text (whatever that text is) in a string, then when the user attempts to edit the textbox content, simply replace whatever text is in the textbox with the contents of the string. Meaning, if the stored (locked) content is “Hello World.” and the user attempts to type in the box, just replace what they type in the “editing” phase with the stored string.

Brent

1 Like