How to prevent first editable Form component ta have focus on Form show?

25 views
Skip to first unread message

Thomas

unread,
Apr 19, 2018, 11:06:29 PM4/19/18
to CodenameOne Discussions
In a Form containing editable components (like TextFields), the first component automatically gains the focus when the Form shows. But there is an issue with TextFields as the virtual keyboard do not automatically shows (at least on Android, I did not test on iOS). This is kind of weird as the user has to click on the TextField that already has the focus (it has the blinking cursor and the text hint, if there is some, do not appear) to see the keyboard to be displayed. I think it would make more sense to display the virtual keyboard if an editable TextField already has gain foccus when a Form shows...
But, in any case, having an auto focus on the first TextField of a Form is not always relevant. For example I have a Form with a search TextField in the Toolbar. The problem is that, when I open this Form, the search Field is automatically focused (and, as a consequence, the text hint is not displayed so the user don't even know what this textfield is for until it clicks somewhere else to make it lose focus...) whereas the user do not necessarily want to perform a search. So I would like to be able to dissable this autofoccus behavior. I tried `form.setEditOnShow(null);` and  `form.setFocused(null);` but with no success. Is there an easy way to do it?

Shai Almog

unread,
Apr 20, 2018, 12:26:16 AM4/20/18
to CodenameOne Discussions
You can call setFocusable(false) which should still allow editing albeit it might cause issues with "next" behavior. You can use the onShow() event to make the field focusable again.

The hint should still be displayed when editing natively. Try setting the theme constant nativeHintBool=true.

You can start editing a field on show using the helper method: form.setEditOnShow(textCmp);
Reply all
Reply to author
Forward
0 new messages