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

For a question of type `checkboxes`, a checkbox item that is both `checked` and `disabled` should be included in the answers

Open odolha opened this issue 8 years ago • 2 comments

In this function: https://github.com/SBoudrias/Inquirer.js/blob/815690c79cce2de1ff56be0ecebf226f972024a5/lib/prompts/checkbox.js#L130-L137 if a choice is disabled it will never be part of the question's answers, even if it is also checked.

This is inconsistent with common behavior. Checkboxes can be both checked and disabled.

I'm surprised I didn't find anything related to this because I think it is quite a common use case. The case is when you want to have some choices forced to be selected by previous answers (but you want to make this clear to the user and avoid the less UX-friendly alternatives like using validation or fixing the answers in the background).

The fix is easy (simply remove the !disabled condition) but I suspect this would break usage that relies on this expectation. Perhaps base the implementation on a configuration option that is off by default :-?.

BTW: the rendering in such cases is also not very nice (no difference between checked && disabled and only disabled) but this can be worked around because of the message we can provide in disabled, e.g. using something like "Required" vs. "Invalid option".

odolha avatar Aug 10 '17 12:08 odolha

Hey, thanks for opening this issue. Looks like a valid use case.

Given you already figured out the solution, would you mind sending a PR? Feel free to also explore UI options.

SBoudrias avatar Aug 10 '17 13:08 SBoudrias

Thanks, @odolha for your notes and initial investigation!

jonscottclark avatar Feb 04 '19 20:02 jonscottclark