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

define question demand (not optional) #1091

Open
sinkcup opened this issue Mar 14, 2022 · 2 comments
Open

define question demand (not optional) #1091

sinkcup opened this issue Mar 14, 2022 · 2 comments

Comments

@sinkcup
Copy link

sinkcup commented Mar 14, 2022

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,
  }
};
@SBoudrias
Copy link
Owner

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'

@sinkcup
Copy link
Author

sinkcup commented Mar 15, 2022

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants