FAQ: native text input field/box usage

Frequently Asked Questions
Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn0

It’s time for another FAQ session! Here are some frequently asked questions:

1. How do the “ended” and “submitted” phases work for native.newTextField() objects?

Here is a summary of how native.newTextField() events works:

  • When the user touches/clicks on the field, the "began" phase occurs and, on mobile devices, the virtual keyboard becomes visible.
  • Typing generates the "editing" phase.
  • If the return/done button is clicked, a "submitted" phase occurs concurrently with an "ended" phase. However, If the user touches a different text field/box, the "ended" phase occurs without the "submitted" phase. Essentially, the "submitted" phase occurs when the user presses the return/done key on the keyboard. It’s intended to indicate that the user has finished text entry and “submitted” the information.
  • On iOS, if you create a text field restricted to numeric input, the numeric keyboard does not have a return/done key to end its input, so you need to provide a standard button or some other means to tell the system that the user has finished entering numbers. At this point, you should call native.setKeyboardFocus() with nil to hide the keyboard which will generate an "ended" phase for the text field object.

2. What happened to the “submitted” event phase for native.newTextBox()?

There is no "submitted" event phase for native.newTextBox() objects. This is because the return/done key generates a new line instead of submitting the content of what was entered. As mentioned in the previous question, you should create a button or other means to indicate that the user has finished entering text.

3. When using native input fields/boxes, how do I hide the keyboard?

To hide the keyboard for either native.newTextField() or native.newTextBox() objects, call native.setKeyboardFocus() with nil. Conversely, you can set focus on either type of native input object by calling native.setKeyboardFocus() with the object’s handle.

4. How can I edit text within a native.newTextBox()?

By default, the text within a native.newTextBox() object is not editable. However, you can easily enable the edit mode by setting object.isEditable to true, where object is the native.newTextBox() object’s handle.

Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn0

This entry has 10 replies

  1. GreenCastle says:

    Is being able to support native textFields and textBoxes in Windows Simulator on the roadmap?

  2. Is it possible to get the char length of the TextBox? Is there a way to tell how many characters are in the text box at one time?

  3. Marc Sockel says:

    Dear Daniel,
    try :

    local textBox = native.newTextBox( 15, 70, 280, 70 )
    textBox.text = “This is a test text box”
    length=string.len (textBox.text)

  4. The “submitted” phase is sent when the user presses the “return” or “done” key on the keyboard. It’s intended to indicate that the user has finished text entry and “submitted” the information. It will not be sent if the user changes focus by clicking on a different field. Before build 904, the Mac Simulator always sent the “submitted” and “ended” phases together (even when the submitted key was not clicked). Starting with build 904, the Mac Simulator now works in a similar way to how iOS and Android works.

  5. MrPakMan says:

    When I type in a text field in non-English (e.g. Korean), Corona processes it as just a set of question marks (i.e. ???…). What should I do to make it compatible with non-English characters?

  6. I just took a quick glance at CoronaLabs’ roadmap but supporting native text inputs in the Windows simulator is not mentioned anywhere. Does this mean it is never going to happen? That’ll be somewhat of a show stopper for me….

  7. frank says:

    Do we have any comment on support of native text inputs in the Windows simulator ? When will that be provided ?

  8. Adam Jones says:

    Please please give us a status update on windows simulator support for these features. This is such a basic feature I can’t believe its not possible for me to do this on windows. Ok, maps I understand is more complex… but a text box?

    The apps I was going to create are going to be a nightmare to make without this support.

  9. Perry says:

    We understand that the lack of native widgets is frustrating but Windows doesn’t permit mixing of native objects and OpenGL surfaces in a way that is useful. We’re looking at alternative solutions but I don’t have an ETA for anything at the moment.

  10. Renato says:

    Thanks for the tutorial Tom.