Comments (10)
Just a heads up we're making good progress on dynamic forms. It looks like the API will be mostly allowing any option Title
, Description
, Option
to be "Func"-able, i.e. take a function to populate the field from. It will automatically cache the options if desired as well.
dynamic-forms.mov
from huh.
You can may be use WithHideFunc
to conditionally show some questions. Here is the rewriten example of #75 (with corrected "Carrot" option for "vegetables" š).
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)
}
from huh.
Hello, Iād like to have a group where I can dynamically add/remove input fields with key bindings (like pressing n
to add a field and pressing d
to remove the current field). Will the work on this issue cover this use case or is it something completely unrelated?
from huh.
Yep, that's definitely something we'll need to support, which also means we'll probably need a spinner if the func
that computes the data runs over a certain time threshold.
from huh.
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
from huh.
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
from huh.
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.
from huh.
Thx for the exemple. So no magic yet here :)
from huh.
+1 to this enhancement!!
from huh.
I would like to extend this request to include external updates such as API calls. I mentioned some details here #183
from huh.
Related Issues (20)
- FR: Support Order/Sorting for FilePicker
- about file picker: support order by name, size, modified time, etc. just like `ls` command
- For Single or Multiple Select, Support Circular Selection
- build stacktrace because `huh` uses refactored `x/exp/term` HOT 1
- Confirm box default to Yes HOT 2
- Confirm button indent at wrong position HOT 3
- FR: Fuzzy find for file picker and select
- Preceding a confirm dialog with a spinner causes the first input keystroke to be ignored HOT 2
- v0.5.0 broke withHide function
- Don't render title row when title is empty
- Feature Request: Validate on a Group
- v0.5.3 breaks Select.Title when options don't fit on the screen
- Allow Cursor option for the filepicker HOT 1
- Looking for help with some issues HOT 2
- `huh.Text`, ^e, open in `$EDITOR`, and Emacs keybindings HOT 1
- Column layout does not show "next" columns after first "screen"
- huh.NewConfirm() proceeds even with validation error
- large title in huh.NewConfirm() breaking alignment HOT 1
- Dynamic fields sometimes don't render when initially switching to a new group
- FR: Enhance FilePicker UX for directory mode
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from huh.