Skip to content

Add "optgroups" #8

Open
Open

Description

@cmckni3
choices = [
  {
    group: 'Colors',
    choices: [...]
  }
]

Activity

  1. cmbankester commented on Sep 11, 2015

    @cmbankester
    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.

  2. cmckni3 commented on Sep 11, 2015

    @cmckni3
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions