Skip to content
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

Feature Suggestion: allow "other" option in list input #1198

Open
queengooborg opened this issue Mar 12, 2023 · 0 comments
Open

Feature Suggestion: allow "other" option in list input #1198

queengooborg opened this issue Mar 12, 2023 · 0 comments

Comments

@queengooborg
Copy link

This was copied from a similar request for python-inquirer -- see magmax/python-inquirer#370

As a part of one of my questions within a script I use, I inquire a reason from the user, which is a list of preset entries, as well as an "Other" entry. In this script, I then check to see if "Other" was selected, and if so, prompt the user for a text input to describe the reason. This looks something like so:

let reason;
const answers = await inquirer.prompt([{
  name: 'reason',
  type: 'list',
  message: "Why is this feature being removed?",
  choices: ['Irrelevant', 'Non-Interface', 'Other']
}]);
reason = answers.reason;

if (reason == "Other") {
  const answers2 = await inquirer.prompt([{
    type: 'input',
    message: "Why is this feature being removed?"
  }]);
  reason = answers2.reason;
}
? Why is this feature being removed?: Other
   Irrelevant
   Non-Interface
 > Other

? Why is this feature being removed?: I just don't like this feature... >:(

I think it would be nice to have an other option (or something similar), that adds an option to the end which doubles as a text input, like so:

const {reason} = await inquirer.prompt([{
  name: 'reason',
  type: 'list',
  message: "Why is this feature being removed?",
  choices: ['Irrelevant', 'Non-Interface'],
  other: 'Other Reason' // default: false, setting to "true" will add "Other"
}]);

// ...or...

const {reason} = await inquirer.prompt([{
  name: 'reason',
  type: 'list',
  message: "Why is this feature being removed?",
  choices: ['Irrelevant', 'Non-Interface', inquirer.ListChoiceOther('Other Reason')],
}]);
? Why is this feature being removed?: Irrelevant
 > Irrelevant
   Non-Interface
   Other

...or...

? Why is this feature being removed?: 
   Irrelevant
   Non-Interface
 > Other: 

...or...

? Why is this feature being removed?: I just don't like this feature... >:(
   Irrelevant
   Non-Interface
 > Other: I just don't like this feature... >:(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant