define question demand (not optional)
now every questions are optional, there is no way to define it demand.
suggestion: add demandOption config, if user select nothing or just press enter, exit error or auto load question to retry.
options = {
things: {
message: 'What do you want to do?',
type: 'checkbox',
choices: ['Order a pizza', 'Make a reservation', 'Bug rate', 'Security'],
demandOption: true,
}
};
Hi, I'm not super clear on your ask.
Do you want to make sure the user select at least one option within the options? If so, I think you can do that safely with a custom validate function.
validate: answers => answers.length > 1 || 'Please select at least one option'
@SBoudrias yes, you are right, if this code can evolve to attribute, it will be better, just like js onblur vs html required:
<input type="text" onblur="alter('please input')" />
to
<input type="text" required />
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required