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
- 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
nilto 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
object is the native.newTextBox() object’s handle.