[GH-ISSUE #571] Switch focus between forms #417

Closed
opened 2026-03-04 01:04:47 +03:00 by kerem · 1 comment
Owner

Originally created by @tramhao on GitHub (Mar 4, 2021).
Original GitHub issue: https://github.com/rivo/tview/issues/571

It's really not that simple.

I have several forms with flex like this:
pic-full-210304-1714-41

and my code is:

	form := tview.NewForm().
		AddInputField("Artist: ", tag.Artist(), 20, nil, nil).
		AddInputField("Title: ", tag.Title(), 20, nil, nil).
		AddInputField("Album: ", tag.Album(), 20, nil, nil).
		// AddFormItem(getTagButton)
		AddButton("Get Tag", nil)

	form.SetFieldBackgroundColor(gomu.colors.popup).
		SetBackgroundColor(gomu.colors.popup).
		SetTitle(node.name).
		SetBorder(true).
		SetBorderPadding(1, 0, 2, 2)
	form2 := tview.NewForm().
		AddDropDown("Lyrics Available: ", options, 0, nil).
		AddButton("Delete Lyric", nil).
		AddButton("Get Lyric2", nil).
		AddButton("Get Lyric3", nil)

	form2.SetFieldBackgroundColor(gomu.colors.popup).
		SetBackgroundColor(gomu.colors.popup).
		SetTitle("Lyric").
		SetBorder(true).
		SetBorderPadding(1, 0, 2, 2)

	lyricFlex := tview.NewFlex().SetDirection(tview.FlexColumn).
		AddItem(form, 40, 0, true).
		AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
			AddItem(form2, 10, 0, true).
			AddItem(lyricTextView, 0, 2, true), 0, 2, true)

The problem is, When I switch focus, I can only do in form, not form2. I know that I need to implement SetInputCapture of last item in form, but in my case, the last one is a button, and cannot get a correct reference by casting.
I got error

impossible type assertion:
        *tview.Button does not implement tview.FormItem (missing GetFieldWidth method)

Some suggestions?

Originally created by @tramhao on GitHub (Mar 4, 2021). Original GitHub issue: https://github.com/rivo/tview/issues/571 It's really not that simple. I have several forms with flex like this: ![pic-full-210304-1714-41](https://user-images.githubusercontent.com/7751505/109940681-4fb15280-7d0d-11eb-812b-2d360cbfbd7c.png) and my code is: ``` form := tview.NewForm(). AddInputField("Artist: ", tag.Artist(), 20, nil, nil). AddInputField("Title: ", tag.Title(), 20, nil, nil). AddInputField("Album: ", tag.Album(), 20, nil, nil). // AddFormItem(getTagButton) AddButton("Get Tag", nil) form.SetFieldBackgroundColor(gomu.colors.popup). SetBackgroundColor(gomu.colors.popup). SetTitle(node.name). SetBorder(true). SetBorderPadding(1, 0, 2, 2) form2 := tview.NewForm(). AddDropDown("Lyrics Available: ", options, 0, nil). AddButton("Delete Lyric", nil). AddButton("Get Lyric2", nil). AddButton("Get Lyric3", nil) form2.SetFieldBackgroundColor(gomu.colors.popup). SetBackgroundColor(gomu.colors.popup). SetTitle("Lyric"). SetBorder(true). SetBorderPadding(1, 0, 2, 2) lyricFlex := tview.NewFlex().SetDirection(tview.FlexColumn). AddItem(form, 40, 0, true). AddItem(tview.NewFlex().SetDirection(tview.FlexRow). AddItem(form2, 10, 0, true). AddItem(lyricTextView, 0, 2, true), 0, 2, true) ``` The problem is, When I switch focus, I can only do in form, not form2. I know that I need to implement SetInputCapture of last item in form, but in my case, the last one is a button, and cannot get a correct reference by casting. I got error ``` impossible type assertion: *tview.Button does not implement tview.FormItem (missing GetFieldWidth method) ``` Some suggestions?
kerem closed this issue 2026-03-04 01:04:48 +03:00
Author
Owner

@tramhao commented on GitHub (Mar 5, 2021):

And now I'm using implementation from:
https://github.com/rivo/tview/issues/100

and works fine thus close this issue.

<!-- gh-comment-id:791095086 --> @tramhao commented on GitHub (Mar 5, 2021): And now I'm using implementation from: https://github.com/rivo/tview/issues/100 and works fine thus close this issue.
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#417
No description provided.