Update input field dynamically from another one #507
-
Hi there :) I am trying to build a simple form with huh and my goal is to update a second input field from a first one but I don't really get how to do it or if it is possible at all. second := huh.NewInput().
Title("second").
Value(secondValue).
Description("the second one")
form := huh.NewForm(
huh.NewGroup(
huh.NewInput().
Title("first").
Value(firstValue).
Description("This is the first input that should set the second one").
second,
),
) Is there any way to update the second one dynamically? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I had a similar issue and I solved it using bubbletea + state. In your case I think something similar would work. It works but it is very clunky and error prone. Hope this makes sense. |
Beta Was this translation helpful? Give feedback.
I had a similar issue and I solved it using bubbletea + state.
In your case I think something similar would work.
In the
Update
you could introspected thefirstValue
and based on that I set thesecondValue
to something. The downside is that this requires to recreate to form again the consequence of that is that your cursor will return back to the first field. I solved this by manually moving the cursor to the right position using theNextField
function.It works but it is very clunky and error prone.
Hope this makes sense.