-
-
Notifications
You must be signed in to change notification settings - Fork 499
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
SelectionPrompt - Set default value not available #508
Comments
@vanheesk SelectionPrompt does not have a default value, since that would mean that the selection prompt is never shown. |
Say I have a SelectionPrompt asking "What is your favorite fruit", and I provide the user with a list of choices. (Apple, Banana, Cherry, Coconut, Dragonfruit). I select "Cherry" and store this somewhere. |
I second this. I use MultiSelectionPrompt to ask the user for a list of permission assigned to a role. When the user is editing the role, I do want to have the already-assigned permissions checked by default. What would be the best way to implement that? I can write the code and make a pull request. |
You can pre-check items. However, you have to add the items one by one. In my code I use something like this: var prompt = new MultiSelectionPrompt<MyItem>()
.Title("Choose items:")
.UseConverter(item => item.Name);
foreach (var item in myItems)
{
if (IsChecked(item))
prompt.AddChoices(item, r => r.Select());
else
prompt.AddChoices(item);
} |
The original question was about SingleSelect specifically, which I solved / worked around using:
|
I would like to see that feature, too. My usecase is: |
I would also love the support of The workaround for us is a bit ugly since we're also having to drop the previous option on the prompt and force the user to verify the select before pressing enter and again at the end of the workflow before changes are saved. Just including a For reference this is what we're having to do at the prompt (simplified)
Once all the settings have been re-confirmed a table is once again displayed with the options from before and after. We're highlighting the "after" options that differ from the originals in yellow and asking the users to verify before selecting yes to save. It's a less than ideal solution but given some users like to use the wizard vs set individual options having a way to default a single select list would be greatly impactful. |
First of all, thanks for a wonderful library! It's working really well. Being able to set a selection default would be really helpful for my purposes too. I'm creating a tool that helps generate StateSmith state machine projects and I want to remember the user's choices from last time. My current thinking for a workaround is to put it at the top with a "remembered" prefix or postfix. |
Are you accepting pull requests for this? I've prototyped a change, and it works well (plus it's a reasonably small change!). It adds a var prompt = new SelectionPrompt<string>()
.Title("Select one")
.AddChoices("First", "Second", "Third")
.DefaultValue("Second");
AnsiConsole.Prompt(prompt);
|
@patriksvensson Are you accepting pull requests for this? |
Dear @reduckted, why wouldn't you just submit it? |
Just following the contribution guidelines. 🤷♂️ |
You are referring to this, right?
Can we please have a nod, @patriksvensson @phil-scott-78? |
nod |
Is your feature request related to a problem? Please describe.
SelectionPrompt does not contain a "Select" -method. It is however available on MultiSelectionPrompt.
Describe the solution you'd like
Option 1:
Add the same "Select" and "IsSelected" -methods (as available in MultiSelectionPromptExtensions) to the SelectionPromptExtensions -class.
Option 2:
Add a "DefaultValue" (as available in TextPrompt) to the SelectionPromptExtensions -class.
Describe alternatives you've considered
I'm currently planning to work around this by setting the selected item as the first one in the list of choices. But that might be confusing for users.
Please upvote 👍 this issue if you are interested in it.
The text was updated successfully, but these errors were encountered: