Native Text Field- Start With Text Entered?

From what I understand from the documentation, you can create a native text field with a x,y,width,height, and listener, but what about with pre-entered text? If not, can we expect to have this added in the near future? 

As it currently stands, I create the text field when a touch even occurs on a Corona Display Object. This creates a new Text field in the desired location, and once the user is finished with their input, it removes the text field and creates a new Corona text object in its place. I’d rather not have to keep the text fields present constantly, due to their many issues compared to a Corona object. 

Examples of use-

  • If a user leaves focus on a text field and goes back to it, the text field can be recreated with previous data
  • A text field with a default text setting
  • User goes back to a previous screen with data inputted. Text fields are recreated with previous info.

Hey, @tylerthedesigner, have you tried myTextField.text property?

http://docs.coronalabs.com/daily/api/type/TextField/text.html

Naomi

Ah. So, it seems that its read only from the event listener attached to the input field, but you can set it externally from the listener. 

Yup, I use it to set the default text, etc.

Glad you worked it out.

Naomi

Ah, I just remembered there’s myTextField.placeholder property.  You may want to play with it too.

It doesn’t show up on API page (or at least I don’t see it), but if you search for “placeholder” on release note page here:

http://developer.coronalabs.com/content/corona-sdk-release-notes-build-2012-840

You’ll see this:

iOS: … Also, adds o.placeholder (string) property for textfields.

I ended up not using placeholder property because I want to have more control over its look and feel, but you might find it useful.

Naomi

I’m trying to use the textField.placeholder property.  Does anyone know how to change the text color for the placeholder text?  I’d like to make it a lighter shade of grey?

Alternatively, does anyone have sample code showing how to use textField.text to accomplish the placeholder functionality?  I can set the .text property to the placeholder text, i.e. “Name”, but can’t get it to disappear once the user touches the text field.  Thanks!

@natelipscomb, try changing .text value to blank (i.e., " ") at “began” phase.  If you want to remove space (i.e., " "), play with event.startPosition during “editing” phase.

Naomi

Hey, @tylerthedesigner, have you tried myTextField.text property?

http://docs.coronalabs.com/daily/api/type/TextField/text.html

Naomi

Ah. So, it seems that its read only from the event listener attached to the input field, but you can set it externally from the listener. 

Yup, I use it to set the default text, etc.

Glad you worked it out.

Naomi

Ah, I just remembered there’s myTextField.placeholder property.  You may want to play with it too.

It doesn’t show up on API page (or at least I don’t see it), but if you search for “placeholder” on release note page here:

http://developer.coronalabs.com/content/corona-sdk-release-notes-build-2012-840

You’ll see this:

iOS: … Also, adds o.placeholder (string) property for textfields.

I ended up not using placeholder property because I want to have more control over its look and feel, but you might find it useful.

Naomi

I’m trying to use the textField.placeholder property.  Does anyone know how to change the text color for the placeholder text?  I’d like to make it a lighter shade of grey?

Alternatively, does anyone have sample code showing how to use textField.text to accomplish the placeholder functionality?  I can set the .text property to the placeholder text, i.e. “Name”, but can’t get it to disappear once the user touches the text field.  Thanks!

@natelipscomb, try changing .text value to blank (i.e., " ") at “began” phase.  If you want to remove space (i.e., " "), play with event.startPosition during “editing” phase.

Naomi

Hi,

can I read direct from file into the text box…

Hi,

can I read direct from file into the text box…

Hello,

I’m using a native.textfield object and would like the focus to remain on the object such that the border does not go away and the user understands that they need to enter a value. I’ve played with the placeholder & text properties but this essentially just predefines a default value and unless the user clicks on that their isn’t any indication that the area is expecting input. If native.textfield isn’t the best object to use for this can someone please let me know a better option, etc?

Thanks

Alex

Just make some frame (some rect for example) around filed and make it visible when there is focus on your input. Hide frame if input loses it’s focus

@Nate31

Check documentation, you can change font, size and color of input text freely

Hello,

I’m using a native.textfield object and would like the focus to remain on the object such that the border does not go away and the user understands that they need to enter a value. I’ve played with the placeholder & text properties but this essentially just predefines a default value and unless the user clicks on that their isn’t any indication that the area is expecting input. If native.textfield isn’t the best object to use for this can someone please let me know a better option, etc?

Thanks

Alex

Just make some frame (some rect for example) around filed and make it visible when there is focus on your input. Hide frame if input loses it’s focus