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

GetValue does not work for Text inputs #63

Closed
farant opened this issue Dec 16, 2023 · 0 comments · Fixed by #64
Closed

GetValue does not work for Text inputs #63

farant opened this issue Dec 16, 2023 · 0 comments · Fixed by #64

Comments

@farant
Copy link

farant commented Dec 16, 2023

Describe the bug
I'm integrating Huh with a Bubbletea app and it seems like m.form.GetValue("field") does not work for Text fields

To Reproduce

type Model struct {
    form *huh.Form // huh.Form is just a tea.Model
}

func NewModel() Model {
    return Model{
        form: huh.NewForm(
            huh.NewGroup(
	        huh.NewText().
		    Key("question").
		    Title("What's your question?"),
            ),
        )
    }
}

func (m Model) Init() tea.Cmd {
    return m.form.Init()
}

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
    // ...

    form, cmd := m.form.Update(msg)
    if f, ok := form.(*huh.Form); ok {
        m.form = f
    }

    return m, cmd
}

func (m Model) View() string {
    if m.form.State == huh.StateCompleted {
        question := m.form.GetString("question")
        return fmt.Sprintf("You selected: %s", question)
    }
    return m.form.View()
}

Expected behavior
question should contain the value of the Text input once it's completed. It is empty. If I change the code to be huh.NewInput(...) getting the value works.

Thanks!

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

Successfully merging a pull request may close this issue.

1 participant