-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic Forms #69
Comments
Hi! This is something we'd to explore in a more official capacity, but for now you can achieve a similar effect using multiple forms. For an example to help get started see #75. |
Thx for the exemple. So no magic yet here :) |
+1 to this enhancement!! |
You can may be use package main
import (
"fmt"
"github.com/charmbracelet/huh"
)
func main() {
var (
category string
choice string
)
huh.NewForm(
huh.NewGroup(
huh.NewSelect[string]().
Title("What are you in the mood for?").
Value(&category).
Options(
huh.NewOption("Some fruit", "fruits"),
huh.NewOption("A vegetable", "vegetables"),
huh.NewOption("A drink", "drinks"),
),
),
huh.NewGroup(
huh.NewSelect[string]().
Title("Okay, what kind of fruits are you in the mood for?").
Value(&choice).
Options(
huh.NewOption("Tangerine", "tangerine"),
huh.NewOption("Canteloupe", "canteloupe"),
huh.NewOption("Pomelo", "pomelo"),
huh.NewOption("Grapefruit", "grapefruit"),
),
).WithHideFunc(func() bool {
return category != "fruits"
}),
huh.NewGroup(
huh.NewSelect[string]().
Title("Okay, what kind of vegetables are you in the mood for?").
Value(&choice).
Options(
huh.NewOption("Carrot", "carrot"),
huh.NewOption("Jicama", "jicama"),
huh.NewOption("Kohlrabi", "kohlrabi"),
huh.NewOption("Fennel", "fennel"),
huh.NewOption("Ginger", "ginger"),
),
).WithHideFunc(func() bool {
return category != "vegetables"
}),
huh.NewGroup(
huh.NewSelect[string]().
Title("Okay, what kind of drinks are you in the mood for?").
Value(&choice).
Options(
huh.NewOption("Coffee", "coffee"),
huh.NewOption("Tea", "tea"),
huh.NewOption("Bubble Tea", "bubble-tea"),
huh.NewOption("Agua Fresca", "agua-fresca"),
),
).WithHideFunc(func() bool {
return category != "drinks"
}),
).Run()
fmt.Printf("One %s coming right up!\n", choice)
} |
I would like to extend this request to include external updates such as API calls. I mentioned some details here #183 |
Yep, that's definitely something we'll need to support, which also means we'll probably need a spinner if the |
Just a heads up we're making good progress on dynamic forms. It looks like the API will be mostly allowing any option dynamic-forms.mov |
Awesome really looking forward to it. I really enjoy working with Huh, it has been great and everyone has been super impressed of the things we used it for |
Hello, I’d like to have a group where I can dynamically add/remove input fields with key bindings (like pressing |
I am aware of the example on conditional form but is there any way to populate the options in a group conditionally as well? @maaslalani |
Dynamics work fine, but since Edit: So to say a "WithHideFunc" per "NewSelect" would be great. |
Is your feature request related to a problem? Please describe.
My current CLI ask several questions to the end user, and each question depends on the choice of the previous one. For instance, select an AWS cluster, then an AWS service.
So I cannot use the form feature of huh (or can I?). Because of this, I cannot display the help message for my prompt.
Describe the solution you'd like
Add a parameter ShowHelpMessage for the fields also.
Describe alternatives you've considered
Create a form for each single question.
Additional context
N/A
The text was updated successfully, but these errors were encountered: