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.
![2024-08-11-081852_hyprshot](https://private-user-images.githubusercontent.com/12776258/356876840-f3e02463-b780-469c-92c6-2864ffe97d18.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxNjg5NjcsIm5iZiI6MTczOTE2ODY2NywicGF0aCI6Ii8xMjc3NjI1OC8zNTY4NzY4NDAtZjNlMDI0NjMtYjc4MC00NjljLTkyYzYtMjg2NGZmZTk3ZDE4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDA2MjQyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY2M2M5YzEyZWMwZWJlZmU2MWJiODFjOWNmZGY2OGI3NGMyZjUyZWVlYTEwMjFiMGYxZGIxN2MxODViYWUxZGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.qxB9L0ACJtKzG-XQCJ8VDXxLCPb26ECx3yU01tWhk_0)
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