It’s Wednesday and time for another FAQ session. Here are five frequently asked questions (FAQ).
1. Why is the “submitted” event phase missing for native.newTextField on devices but it’s working on the Mac Simulator?
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.
2. I’m confused about the “ended” and “submitted” phases for native.newTextFields.
Here is a summary of how TextField events works. When the user touches/clicks on a TextField, the “began” phase is sent and the keyboard is visible. Typing generates the “editing” phase. If the return/done button is clicked, a “submitted” phase is sent followed by the “ended” phase. If the user touches another TextField (or TextBox), the “ended” phase is sent (without the “submitted” phase).
On iOS if you create a TextField for numbers, the number keyboard does not have a return key to end the input so you need to provide a button that the user presses when done. You would call native.setKeyboardFocus with nil to hide the keyboard. Hiding the keyboard will generate an “ended” phase for that TextField object.
Note: What I described above only works on the Mac Simulator starting with build 904.
3. What happened to the “submitted” event phase on native.newTextBox?
There is no submitted event phase with newTextBox. The reason is the return key generates a new line instead of submitting the content of what was entered. As mentioned in the previous question, you need to create a button that the user can press when they are finished.
4. When using native.newTextField, how do I hide the keyboard?
To hide the keyboard on either native.newTextField or native.newTextBox, call native.setKeyboardFocus with nil. Conversely, you can set focus on either type of native text objects by calling native.setKeyboardFocus with the text object’s handle.
5. How can I edit text in the native.newTextBox?
By default the native.newTextBox is not editable. You can enable the edit mode by setting object.isEditable = true (where “object” is the native.newTextBox handle).
That’s it for today’s questions. I hope you enjoyed it and even learned a few things.
Posted by Tom Newman. Thanks for reading...