Giter VIP home page Giter VIP logo

Comments (4)

AlecAivazis avatar AlecAivazis commented on May 30, 2024 1

@ahmetb i'm going to close this now since the settable interface is now merged. Also, #92 should handle the int -> string conversions in the deeply nested cases (as in the MultiSelect example you shared above)

from survey.

AlecAivazis avatar AlecAivazis commented on May 30, 2024

Hey @ahmetb thanks for the detailed use case, I'm personally not a fan of returning an index from the list of options in a multi select prompt because i think it would create 2 different ways of retrieving data from a multi select which I think unnecessarily overcomplicates the API. Instead would like to add support for []int in the case where the options are []string{"1", "2", "3"} and the answers would then be converted to the right types.

I recognize this doesn't solve your issue so let I suggest implementing the interface described here and put the transformation from a list of strings to products in the interface method.

from survey.

AlecAivazis avatar AlecAivazis commented on May 30, 2024

Another feature that could be added to support your usecase is having an object that allows for a different displayed question from the one that is returned by the prompt. This could look like

survey.MultiSelect{
    Message: "which products do you want?",
    Options: {}survey.Option{
        {Display: "ProductName1", Value: 123},
        {Display: "ProductName2", Value: 514},
    }
}

from survey.

ahmetb avatar ahmetb commented on May 30, 2024

Your suggestion sounds interesting, how about instead of a well defined struct, accepting something like []fmt.Stringer (or []survey.Option , which would be an interface that requires func DisplayName() string?

In your example, I would probably use Value to store indexes.

from survey.

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.