-
Notifications
You must be signed in to change notification settings - Fork 167
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
Optgroup feature for select and multipleSelect Widgets #145
Conversation
Instead of: choices: {
foo: 'bar',
group1: {
label: 'Hamster Dance',
choices: {
1: 'one',
2: 'two'
}
}
} as a data format to create an choices: {
foo: 'bar',
'Hamster Dance': {
1: 'group1:one',
2: 'group1:two'
}
} That might be more compact, and also would remove the implicit value munging that happens with "group1", and might also make the implementation a bit cleaner? |
Your suggestion looks like my first attempt (which I tried locally) - but that made it harder to have just one function to render the options and made the code quite ugly. I also found it nice to have an option to specify the label explizit. Regarding the value munging - you're right, I also don't like it, but it would still be needed in the case were the options are passed as an array:
But I'm fine with your suggestion - that would mean that arrays can't be used in these cases. Cheers |
I don't think the options should ever be passed as an array - imo the value and text should always be explicitly specified, which requires an object (since string parsing is an antipattern). |
Ok ... then I'll go with your suggestion. But the new patch has to wait until tomorrow |
ef107e2
to
68f0463
Compare
I've adjusted the code and extended the tests a bit. |
} | ||
function choicesHTML(choices, value) { | ||
return Object.keys(choices).reduce(function (html, k) { | ||
if (typeof choices[k] == 'object') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use is.object(choices[k])
here - typeof null
is "object", and please always avoid ==
in any circumstances.
Other than these two comments, this looks great. Thanks! |
68f0463
to
8d97362
Compare
@tolleiv Not sure how this fell through the cracks - can you freshly rebase it on top of latest master if you're still interested in landing it? |
Hi,
thanks for this great form framework. I missed an option to have "optgroups" within the select widgets and therefore added an option to have them.
For now I've kept the functions to render the groups and options separate per widget, but that could be refactored later on to have a single rendering function for both.
I've also added basic tests, which also show the configuration syntax.
Would be great to get your feedback.
Cheers,
Tolleiv