Skip to content

#Question, how to add add screen elements dynamically #397

@shaunenslin

Description

@shaunenslin

Hi

I am battling to get this right. I have a flex grid on the screen and am asking them to make a choice. So, in essence

I create a flex and in it, put a dropdown.
Based on the dropdown answer, I want to ask a different question, but want to simply add the next question to the flex.

eg. Kind of like below, so when a selection is made on the ssdropdown, I want to add the ltdropdown to the flexgrid. I have used app.Draw() to try refresh the screen, but the ltdropdown never appears on the screen

func a() {
	app := tview.NewApplication()
	flex := tview.NewFlex()
	ssdropdown := tview.NewDropDown().
		SetLabel("Select from the available source systems: (hit Enter): ").
		SetOptions(strings.Split("Syspro,Pastel", ","), nil)
	ssdropdown.SetSelectedFunc(func(text string, index int) {
		ltdropdown := tview.NewDropDown().
			SetLabel("Will this be a live or test system? (hit Enter): ").
			SetOptions([]string{"TEST", "QA", "LIVE"}, nil)
		flex.AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
			AddItem(ltdropdown, 1, 0, true),
			1, 0, false)
		app.Draw()
	})
	if err := app.SetRoot(flex, true).SetFocus(ssdropdown).Run(); err != nil {
		panic(err)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions