Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
How to set the focus on a TextField?
-
Hi, is there any way to set the focus on input elements in UI Views? I have created a view containing a TextField and a WebView. I'd like to enter commands in the TextField with a Bluetooth keyboard and show the results of these commands in the WebView. It is quite annoying that whenever I hit the return key I need to use my finger to set the focus to the TextField again. Please, how can I do this automatically?
-
Tab key?
-
Sadly, the Tab key does not work, at least not in a Pythonista app.
-
Hmm, good idea, but that doesn't work. I was just wondering, because in console mode the cursor stays in the input field after pressing enter, allowing for continuous typing without having to take my hands away from the keyboard. It would be nice if ui.TextField could show the same behaviour.
-
You could use
TextField.begin_editing()
if that's what you're looking for.In the delegate for your textfield, after you do whatever it is that hitting the enter key currently does put
textfield.begin_editing()
to return focus to the TextField. -
Thank you very much! The problem was that I had copied the delegate example for the TextField from the documentation, but overlooked that it contains a call to
textfield.end_editing()
in thetextfield_should_return
delegate method. Now that I have removed the line it works! -
I'm glad that works for him, but for me the original problem remains: How to I set the focus to a TextField or TextView when loading a sheet?
-
@robinsiebler
textfield.begin_editing()
doesn't work? -
It works. I don't know what I was thinking before.