[GH-ISSUE #650] tview.Form functions are not triggered tview.NewFlex layout #477

Closed
opened 2026-03-04 01:05:20 +03:00 by kerem · 2 comments
Owner

Originally created by @davidpatters0n on GitHub (Sep 16, 2021).
Original GitHub issue: https://github.com/rivo/tview/issues/650

I've found that when a button/form is added as an item to a tview.Newflex layout the actions will not trigger. Examples:

package main

import (
	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	form := tview.NewForm().
		AddDropDown("Title", []string{"Mr.", "Ms.", "Mrs.", "Dr.", "Prof."}, 0, nil).
		AddInputField("First name", "", 20, nil, nil).
		AddInputField("Last name", "", 20, nil, nil).
		AddCheckbox("Age 18+", false, nil).
		AddPasswordField("Password", "", 10, '*', nil).
		AddButton("Save", nil).
		AddButton("Quit", func() {
			app.Stop()
		})
	form.SetBorder(true).SetTitle("Enter some data").SetTitleAlign(tview.AlignLeft)

	flex := tview.NewFlex().
		AddItem(tview.NewBox().SetBorder(true).SetTitle("Left Side"), 0, 1, false).
		AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
			AddItem(form, 16, 2, false).
			AddItem(tview.NewBox().SetBorder(true).SetTitle("Bottom Pane"), 0, 1, false), 0, 3, false)

	if err := app.SetRoot(flex, true).Run(); err != nil {
		panic(err)
	}
}

Recordings

Form declared not using tview.NewFlex()

Form declared using tview.NewFlex()

Originally created by @davidpatters0n on GitHub (Sep 16, 2021). Original GitHub issue: https://github.com/rivo/tview/issues/650 I've found that when a button/form is added as an item to a `tview.Newflex` layout the actions will not trigger. Examples: ```go package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() form := tview.NewForm(). AddDropDown("Title", []string{"Mr.", "Ms.", "Mrs.", "Dr.", "Prof."}, 0, nil). AddInputField("First name", "", 20, nil, nil). AddInputField("Last name", "", 20, nil, nil). AddCheckbox("Age 18+", false, nil). AddPasswordField("Password", "", 10, '*', nil). AddButton("Save", nil). AddButton("Quit", func() { app.Stop() }) form.SetBorder(true).SetTitle("Enter some data").SetTitleAlign(tview.AlignLeft) flex := tview.NewFlex(). AddItem(tview.NewBox().SetBorder(true).SetTitle("Left Side"), 0, 1, false). AddItem(tview.NewFlex().SetDirection(tview.FlexRow). AddItem(form, 16, 2, false). AddItem(tview.NewBox().SetBorder(true).SetTitle("Bottom Pane"), 0, 1, false), 0, 3, false) if err := app.SetRoot(flex, true).Run(); err != nil { panic(err) } } ``` ## Recordings ### Form declared not using `tview.NewFlex()` ✅ ![](http://g.recordit.co/LEcz39zD3r.gif) ### Form declared using `tview.NewFlex()` ❌ ![](http://g.recordit.co/woFbNvTJTe.gif)
kerem closed this issue 2026-03-04 01:05:20 +03:00
Author
Owner

@rivo commented on GitHub (Sep 27, 2021):

If you enable the mouse, your example code works:

if err := app.SetRoot(flex, true).EnableMouse(true).Run(); err != nil {
	panic(err)
}
<!-- gh-comment-id:927770205 --> @rivo commented on GitHub (Sep 27, 2021): If you enable the mouse, your example code works: ```go if err := app.SetRoot(flex, true).EnableMouse(true).Run(); err != nil { panic(err) } ```
Author
Owner

@davidpatters0n commented on GitHub (Oct 1, 2021):

Closing since this was what was missing.

<!-- gh-comment-id:932088541 --> @davidpatters0n commented on GitHub (Oct 1, 2021): Closing since this was what was missing.
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#477
No description provided.