GithubHelp home page GithubHelp logo

Comments (5)

maaslalani avatar maaslalani commented on September 27, 2024 1

I think the correct solution here would be to take the union of the two defaults. In this case all three would be selected as lettuce is in the toppings and the other two are selected.

Really good call on catching this intended behaviour btw! Thank you so much!

from huh.

maaslalani avatar maaslalani commented on September 27, 2024

Hey @Iilun, this is possible if you set the variable to the default value you want:

value := "default value"

huh.NewInput().Value(&value).Run()

The field will be pre-filled with the value ("default value")

from huh.

vitor-mariano avatar vitor-mariano commented on September 27, 2024

@maaslalani All the fields can be prefilled with Value(&value), except Select and MultiSelect. I know I can achieve the same behavior with huh.NewOption(...).Selected(true), but not with huh.NewOptions. Is this on purpose? Using Value(&value) would be interesting in scenarios when editing existing data and keeping consistency with other field types.

If this behavior is not intended, I'd love to open a PR fixing it!

from huh.

maaslalani avatar maaslalani commented on September 27, 2024

Hey @vitor-mariano, yes we'd love to accept a PR that inspects the default value of select and multi-select and pre-selects the values.

toppings := []string{"lettuce", "tomatoes"}

huh.NewMultiSelect().Options(huh.NewOptions("lettuce", "tomatoes", "cheese")).Value(&toppings).Run()
// first two should be selected

from huh.

vitor-mariano avatar vitor-mariano commented on September 27, 2024

@maaslalani before moving forward with the fix, what should happen if I have both value and Selected(true)? Eg

huh.NewMultiSelect().
    Options(
        huh.NewOption("lettuce", "lettuce"),
        huh.NewOption("tomatoes", "tomatoes").Selected(true),
        huh.NewOption("cheese", "cheese").Selected(true),
    ).
    Value(&toppings).
    Run()

from huh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.