Getting the currently focused index/item in a Select #355
Closed
therealphatmike
started this conversation in
General
Replies: 1 comment
-
I solved my own discussion here. Apologies for opening and closing a discussion so quickly. I didn't see the For anyone curious I just added an accessor to my model, passed the accessor into the form, and then used focused := new(databases.Database)
accessor := huh.NewPointerAccessor(focused)
return SelectDatabase{
ready: true,
width: width,
height: height,
selectableDbs: availableDbs,
accessor: accessor,
form: huh.NewForm(
huh.NewGroup(
huh.NewSelect[databases.Database]().
Title("Which database would you like to connect to?").
Key("database").
Accessor(accessor).
Options(dbOptions...),
),
),
} func (m SelectDatabase) View() string {
// do any prep
highlightedDb := m.accessor.Get()
// render your content with highlightedDb
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey all,
I can't seem to find a way to get the currently focused index or item from a select list. I have a select list on the left with just a simple name field, and as the user arrows through the form, I would like to render expanded information on the right. Is there a way to achieve this without having the user press enter? I would prefer the experience to not require the user to hit enter twice to fully select an option.
Here's a screen shot as an example, as you can see my MySQL entry is selected but the PG db info still gets rendered.
So far the only way I could find to do this would be to force the user to make the selection so it updates form state and I could retrieve it with
m.Form.GetInt("database")
and then update the expanded view. But then to select and connect to the DB, the user has to hit enter again and I have to force the model into some intermediary state in the interim. I did a search and did not find what I was looking for in docs, examples, or discussions.Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions