[GH-ISSUE #144] How to manage form items focus change? #114

Closed
opened 2026-03-04 01:02:03 +03:00 by kerem · 5 comments
Owner

Originally created by @stephencheng on GitHub (Jul 27, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/144

I have got mixed of input field and dropdown items, plus a ok and cancel buttons.

When I use my own selected like this:

selected func(){
app.SetFocus(nextitem)
}
func (d *DropDown) SetOptions(texts []string, selected func(text string, index int)) *DropDown

Then I found it somehow changes the behaviour of auto focus change order. It either just stop working when you type Tab key or back Tab, or it jumps to cancel button, and skip itself in the first loop cycle of focus change when you keep press Tab. It restores the order in the second loop of focus change. Similarly the behaviour of pressing back Tab to switch focus change is disturbed too.

Is this expected?

Also with above implementation, I could simply type enter for each form item, eg dropdown or inputfield, but I couldn't do the same for the last input item because each item will require previous item being created prior to SetFocus(aCreatedItem). I can't create a button and associate the selected func with it until I use the form.AddButton to create it and add the selected func, because that function requires the reference of last input item to get value. It's sort of cyclic loop.

So is there a feature/way to auto jump to next form item without putting my own code ? or I missed something here?

Thanks

Originally created by @stephencheng on GitHub (Jul 27, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/144 I have got mixed of input field and dropdown items, plus a ok and cancel buttons. When I use my own selected like this: > selected func(){ > app.SetFocus(nextitem) > } > func (d *DropDown) SetOptions(texts []string, selected func(text string, index int)) *DropDown Then I found it somehow changes the behaviour of auto focus change order. It either just stop working when you type Tab key or back Tab, or it jumps to cancel button, and skip itself in the first loop cycle of focus change when you keep press Tab. It restores the order in the second loop of focus change. Similarly the behaviour of pressing back Tab to switch focus change is disturbed too. Is this expected? Also with above implementation, I could simply type enter for each form item, eg dropdown or inputfield, but I couldn't do the same for the last input item because each item will require previous item being created prior to SetFocus(aCreatedItem). I can't create a button and associate the selected func with it until I use the form.AddButton to create it and add the selected func, because that function requires the reference of last input item to get value. It's sort of cyclic loop. So is there a feature/way to auto jump to next form item without putting my own code ? or I missed something here? Thanks
kerem closed this issue 2026-03-04 01:02:03 +03:00
Author
Owner

@rivo commented on GitHub (Jul 27, 2018):

Regarding the first part, are you sure you're not interfering with the form's behaviour in other places? I have trouble seeing a connection between the selected attribute of a DropDown and the form overall. Can you send more code that illustrates what you're doing? (Preferably a short code snippet that I can run.)

Regarding the second part, there's no "auto jump" for items except the Tab key. I'm not sure why you would want to skip the Tab key in the first place. But I don't really understand what you're trying to do anyway and at what point the existing functionality of Form is insufficient to you.

<!-- gh-comment-id:408457307 --> @rivo commented on GitHub (Jul 27, 2018): Regarding the first part, are you sure you're not interfering with the form's behaviour in other places? I have trouble seeing a connection between the `selected` attribute of a `DropDown` and the form overall. Can you send more code that illustrates what you're doing? (Preferably a short code snippet that I can run.) Regarding the second part, there's no "auto jump" for items except the Tab key. I'm not sure why you would want to skip the Tab key in the first place. But I don't really understand what you're trying to do anyway and at what point the existing functionality of `Form` is insufficient to you.
Author
Owner

@stephencheng commented on GitHub (Aug 8, 2018):

Thanks.

I think the feature I liked would mess up things around. I will probably just use tab key to shift the focus around.

<!-- gh-comment-id:411250800 --> @stephencheng commented on GitHub (Aug 8, 2018): Thanks. I think the feature I liked would mess up things around. I will probably just use tab key to shift the focus around.
Author
Owner

@stephane-martin commented on GitHub (Apr 19, 2019):

Got a similar problem.

I have a form with a few input fields and a Confirm button. When the user selects the Confirm button, some validation stuff happens (the kind of validation that can not be dealt with an acceptance func).

For example, there is a URL input field. When the user confirms, it checks that the URL field indeed contains a well-formed URL. If it is validated, close the form and proceed. If it not validated, it shifts the focus back to the URL field so that the user can fix it (using application.SetFocus(urlInputField).

The problem is that, after fixing the URL, when the user hits TAB to navigate to the confirm button again, the form seems to believe the focus is still on the Confirm button, so the focus then goes to the wrong field.

<!-- gh-comment-id:485037294 --> @stephane-martin commented on GitHub (Apr 19, 2019): Got a similar problem. I have a form with a few input fields and a Confirm button. When the user selects the Confirm button, some validation stuff happens (the kind of validation that can not be dealt with an acceptance func). For example, there is a URL input field. When the user confirms, it checks that the URL field indeed contains a well-formed URL. If it is validated, close the form and proceed. If it not validated, it shifts the focus back to the URL field so that the user can fix it (using `application.SetFocus(urlInputField)`. The problem is that, after fixing the URL, when the user hits TAB to navigate to the confirm button again, the form seems to believe the focus is still on the Confirm button, so the focus then goes to the wrong field.
Author
Owner

@rivo commented on GitHub (Aug 29, 2019):

I know this comes very late. But the latest commit should fix your issue.

<!-- gh-comment-id:526257264 --> @rivo commented on GitHub (Aug 29, 2019): I know this comes very late. But the latest commit should fix your issue.
Author
Owner

@stephane-martin commented on GitHub (Aug 29, 2019):

Never too late :o) Thank you

<!-- gh-comment-id:526279155 --> @stephane-martin commented on GitHub (Aug 29, 2019): Never too late :o) Thank you
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#114
No description provided.