Skip to content
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

Broken behavior when using multiple Select with OptionsFunc #500

Open
tetienne opened this issue Dec 20, 2024 · 0 comments
Open

Broken behavior when using multiple Select with OptionsFunc #500

tetienne opened this issue Dec 20, 2024 · 0 comments

Comments

@tetienne
Copy link

Describe the bug
I want to be able to have multiple Select within the same form where the options from one select depends on the selected option from the previous select.

To Reproduce

                var i int
		var j int
		var k int

		form := huh.NewForm(
			huh.NewGroup(
				huh.NewSelect[int]().
					Title("Select a 1st number").
					Options(huh.NewOptions([]int{1, 2, 3, 4}...)...).
					Value(&i),
				huh.NewSelect[int]().
					Title("Select a 2nd number").
					OptionsFunc(func() []huh.Option[int] {
						var t []int
						for _, v := range []int{1, 2, 3, 4} {
							t = append(t, v*i)
						}
						return huh.NewOptions(t...)
					}, &i).
					Value(&j),
				huh.NewSelect[int]().
					Title("Select a 3rd number").
					OptionsFunc(func() []huh.Option[int] {
						var t []int
						for _, v := range []int{1, 2, 3, 4} {
							t = append(t, v*j)
						}
						return huh.NewOptions(t...)

					}, &j).
					Value(&k),
			),
		)
		err := form.Run()

Expected behavior
The last Select is always updated.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser N/A
  • Version N/A

Smartphone (please complete the following information):

  • Device: N/A
  • OS: N/A
  • Browser N/A
  • Version N/A

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant