Context
This came up while evaluating @clack/prompts as a potential replacement for enquirer.js, comparing it with enquirer.js and @inquirer/prompts.
Split out from: #550
Problem
multiselect has a required option with a built-in validation message:
Please select at least one option
That message is not customizable, and there is no general validation hook for select-like prompts.
In enquirer.js, this kind of validation can be customized:
validate(value) {
if (value.length === 0) return 'You must choose at least one package.'
return true
}
Proposal
Add a validate option to select-like prompts, initially multiselect and groupMultiselect:
const selected = await multiselect({
message: 'Choose packages',
options: [...],
validate: (values) => {
if (values.length === 0) return 'Select at least one package.'
return true
},
})
The validation function could return true or a string error message.
Notes
This could either replace or complement the current required option.
Context
This came up while evaluating
@clack/promptsas a potential replacement forenquirer.js, comparing it withenquirer.jsand@inquirer/prompts.Split out from: #550
Problem
multiselecthas arequiredoption with a built-in validation message:That message is not customizable, and there is no general validation hook for select-like prompts.
In
enquirer.js, this kind of validation can be customized:Proposal
Add a
validateoption to select-like prompts, initiallymultiselectandgroupMultiselect:The validation function could return
trueor a string error message.Notes
This could either replace or complement the current
requiredoption.