Inquirer.js icon indicating copy to clipboard operation
Inquirer.js copied to clipboard

Allow questions can be marked as mandatory

Open aztack opened this issue 3 years ago • 2 comments

releated issue: https://github.com/SBoudrias/Inquirer.js/issues/1091

options = {
  things: {
    message: 'App name?',
    type: 'input',
    required: true
  }
};

If a user does not provide a non-empty app name, keep asking the same question.

aztack avatar Aug 15 '22 11:08 aztack

Today you can use the validate function for this, check the input and make sure there is content; if not return an error message.

I'm leaning towards not augmenting the API with this extra option because:

  1. required would only work on input type prompt
  2. We'd need to decided how to handle getting both required and validate on that prompt
  3. This add an extra internal content that isn't translated; and this has been a recurring issue for international users of the library.

SBoudrias avatar Aug 15 '22 12:08 SBoudrias

I'm revising my opinion in 2024. I'd be happy to add a required property to the new @inquirer/input - with similar implementation to the same option on the checkbox prompt: https://github.com/SBoudrias/Inquirer.js/tree/master/packages/checkbox

SBoudrias avatar Apr 04 '24 21:04 SBoudrias