Skip to content

Credit card form example - validation not working? #1146

Answered by AdditionAddict
jasonlotz asked this question in Q&A
Discussion options

You must be logged in to vote

yeah, example doesn't show errors in the tui

huh has ability to show errors via validate
https://pkg.go.dev/github.com/charmbracelet/huh#section-readme

    // Gather some final details about the order.
    huh.NewGroup(
        huh.NewInput().
            Title("What’s your name?").
            Value(&name).
            // Validating fields is easy. The form will mark erroneous fields
            // and display error messages accordingly.
            Validate(func(str string) error {
                if str == "Frank" {
                    return errors.New("Sorry, we don’t serve customers named Frank.")
                }
                return nil
            }),

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@jasonlotz
Comment options

Answer selected by jasonlotz
Comment options

You must be logged in to vote
1 reply
@jasonlotz
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants