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

Allow disabled choices #197

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Allow disabled choices #197

wants to merge 2 commits into from

Conversation

TomKremer
Copy link

Set the third value in choices to TRUE to disable an item on the list.

Signed-off-by: Tom Kremer <[email protected]>
Copy link
Collaborator

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently isn't passing the linter, and would need tests.

In general, I like this addition!

lib/widgets.js Outdated
var renderData = isNested ?
{ isNested: true, label: choice[0], choices: choice[1] } :
{ isNested: false, value: choice[0], label: choice[1] };
if (choice.length == 3) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure we need this branching - we can just set disabled to false unless a third truthy value is provided.

- Accept a 4th param for the default option
- Update Test

Signed-off-by: Tom Kremer <[email protected]>
@@ -57,8 +57,8 @@ var renderChoices = function (choices, renderer) {
return reduce(choices, function (partialRendered, choice) {
var isNested = is.array(choice[1]);
var renderData = isNested ?
{ isNested: true, label: choice[0], choices: choice[1] } :
{ isNested: false, value: choice[0], label: choice[1] };
{ isNested: true, label: choice[0], choices: choice[1], disabled: choice[2], default: choice[3] } :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is "default"? let's keep this PR just to adding "disabled".

@kmohrf
Copy link
Contributor

kmohrf commented Dec 30, 2016

i gotta comment even though I’m not a maintainer but it’s my code you’re changing :).

i like the idea, but apart from the fact, that this change only provides an array syntax for specifying disabled options, i always feel like options that use designated array indexes are hard to remember and force developers to look at the docs a lot because they forgot which option is which array-index. the wish to omit the disable or default flag (this pr introduces both as of now) and the need to have special values to skip an array index is another problem i see with this implementation.

why not keep the current format as it is and add defaults and disabled values as individual field options? iirc values are unique for each field and you could just build object where choice values map to default values/ disabled flags. that’d be backwards compatible, easy to remember and you probably would’t have to touch any code beside the choice renderer.

btw. how do you see choice defaults working out? i might be mistaken but I don’t see the point because you already have full control over the values as the user simply selects given choices.

@ljharb
Copy link
Collaborator

ljharb commented Dec 30, 2016

I haven't truly yet understood this PR, but I agree that anything that requires remembering or matching array indices is just not a good API.

@ljharb ljharb marked this pull request as draft January 19, 2021 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants