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

Add "optgroups" #8

Open
cmckni3 opened this issue Mar 28, 2014 · 2 comments
Open

Add "optgroups" #8

cmckni3 opened this issue Mar 28, 2014 · 2 comments

Comments

@cmckni3
Copy link
Collaborator

cmckni3 commented Mar 28, 2014

choices = [
  {
    group: 'Colors',
    choices: [...]
  }
]
@cmbankester
Copy link
Contributor

Hmm. Interesting idea, and it could be super useful, but we should think about the implementation a little bit. Maybe something like this:

$(selector).immybox({
  choices: [
    {text: 'An ungrouped choice', value: 'something'},
    {text: 'A group', choices: [
      {text: 'A grouped choice', value: 'something_else'},
      ...
    ]}
    ...
});

Formally, the choices initialization option can only be an array of choices, where choice is an object with the following structure:

{
  text: String, // required
  value: Object, // optional; if missing, choice is a "group"
  choices: Array // optional; ignored if choice is not a "group"; if choice is a "group", elements of this array must be modified_choice elements
}

and modified_choice is an object with the following structure:

{
  text: String, // required
  value: Object, // required
}

An alternative might be to simply use the value option of choices as either the value associated with the choice (if it's not a "group"), or the choices array (if it is a "group"), and have the choice's "group" status be dictated by another option on the choice object, say is_group: Boolean.

Yet another approach would be to use two different initialization options, e.g.:

$(selector).immybox({
  groups: [
    {text: 'A Group', value: 'some_group'}
  ],
  choices: [
    {text: 'An ungrouped choice', value: 'something'},
    {text: 'A grouped choice', value: 'something_else', group_value: 'some_group'}
    ...
});

That option would be the cleanest to use, IMO, but the most difficult to implement since it would require parsing the choices into groups.

@cmckni3
Copy link
Collaborator Author

cmckni3 commented Sep 11, 2015

I like the last option the most as well but it is definitely a little more involved to implement.

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