-
I have added functionality to a small app to move from field to field with the enter key instead of tab, and when a button is the next field, execute the action for that button and move to the next appropriate Input field. I've minimized the code to essentials in attached to show the behavior in Reset button of this app moving to the #field_client_id when clicked with the mouse as expected, but when using the enter key when the Reset button is focused, it moves to #field_client_name instead. Discussion in Discord #help-wanted channel just prior to this posting. For full code (does not have json file code and custom module stripped and likely will not run without them): https://github.com/apeaveysf/demo_label_printer |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Thanks! As mentioned on Discord, I think there's a tidy workaround to be had here, and perhaps some changes to Textual in the longer-term that will make this easier and more obvious. End of office hours for me right now but I hope to return to this later this evening or in the morning. :-) |
Beta Was this translation helpful? Give feedback.
-
Looking at this a bit more now, the first thing I'd suggest is that, rather than hooking into the key event to turn def on_input_submitted(self, event: Input.Submitted ) -> None:
next_input = {
"field_label_printer": "client_id",
"field_client_id": "client_name",
"field_client_name": "alias",
"field_alias": "tests",
"field_tests": "date",
"field_date": "quantity",
"field_quantity": "label_printer"
}[ event.input.id ]
self.set_focus( self.query_one( f"#field_{next_input}", Input ) ) As for the specific issue, if focus going to the second field when This is better illustrated if I add some debugging to the On the other hand, if I use the enter key on the reset button, it really does look like focus moves to the first field, as per While something like #1196 would greatly simplify what I did in the (kinda klunky) implementation of I'll narrow this down to the smallest test example possible and raise an issue for us to look at. |
Beta Was this translation helpful? Give feedback.
Looking at this a bit more now, the first thing I'd suggest is that, rather than hooking into the key event to turn
Enter
into the "move to next field" method, it might make a bit more sense to use the input submitted event. Possibly not the most elegant way, but a quick first play here suggests something like this perhaps: