How to use multiple forms within a BubbleTea app #115
Replies: 3 comments
-
For reference, I kind of got it working after using m.detailedForm.Run(), not sure if there is a better way of doing it. ...
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type)
...
case loadDeviceDB:
if msg.Err != nil {
m.err = msg.Err
return m, nil
}
m.deviceStatus = msg.status
m.deviceInit = true
if msg.status != "new" {
m.deviceExists = true
if !m.detailedFormInit {
m.detailedForm.Run()
m.detailedFormInit = true
}
}
return m, nil
... If I do this the form is displayed correctly and I can navigate the list with keys/confirm choice. |
Beta Was this translation helpful? Give feedback.
-
Id like to add another question that I feel is related as its very relevant to using multiple forms. What would be the best way to have dynamic questions/descriptions in my secondary form(s)? For example, instead of saying: ...
m.detailedForm = huh.NewForm(huh.NewGroup(
huh.NewSelect[string]().
Title("Device already exists in database").
... Id like to include the device name (m.deviceName). That variable is however empty when the Model is initialized in my |
Beta Was this translation helpful? Give feedback.
-
I think this post can be deleted as it's probably more confusing than helping in its current state. Still interested in a solution of dynamic questions/descriptions but I think its better that I post that as a separate topic . |
Beta Was this translation helpful? Give feedback.
-
Hi,
To preface this i'm very new to writing Go but after finding all the cool CLI tools available like Bubbletea, Lipgloss and now huh I had to give it a try.
I'm trying to build a TUI where we ask the user for a device, do some checks and depending if the device already exist I want to display a second form with additional questions for the user.
My Problem
Generating and displaying a second form depending on previous input data works, but navigating it does not. In a NewSelect-group I can't go up/down/confirm an option in the list.
If I change the order so detailedForm is displayed first it works so I must be doing something wrong here..
Code:
Beta Was this translation helpful? Give feedback.
All reactions