questionary icon indicating copy to clipboard operation
questionary copied to clipboard

Add possibility to use List[Choice] in choices parameter of autocomplete

Open oferveur opened this issue 3 years ago • 3 comments

Describe the problem

It will be valuable to have the possibility to use Choice inside the parameter "choices". It will allow for exemple to select a object.

Describe the solution

from questionary.prompts.common import Choice
from questionary import autocomplete
from dataclasses import dataclass

@dataclass
class Object:
    name: str
    value : str
object1 = Object("titre1", "value1")
object2 = Object("titre1", "value1")
choices = [
    Choice(object1.name, value=object1),
    Choice(object2.name, value=object2)
]
autocomplete("select object instance:", choices=choices)

Alternatives considered

No response

oferveur avatar Jan 25 '22 08:01 oferveur

@oferveur mhm I am not actually sure if there is something that stands in the way of doing that. happy to take a look, but maybe @kiancross knows if there is an issue with the suggested solution? I think in terms of API / workflow it does fit in quite well.

tmbo avatar Feb 22 '22 14:02 tmbo

@tmbo I think the only problem would be deciding what the checked, disabled, and shortcut_key properties of a Choice do in the context of an autocomplete. I do agree that at least being able to set a different title and value would be useful.

kiancross avatar Feb 23 '22 19:02 kiancross

Came to see if this functionality existed, consider this a +1 for interest in how we can achieve this

awgymer avatar Nov 29 '22 22:11 awgymer