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

Support optgroup #23

Closed
ghost opened this issue Nov 15, 2012 · 5 comments
Closed

Support optgroup #23

ghost opened this issue Nov 15, 2012 · 5 comments

Comments

@ghost
Copy link

ghost commented Nov 15, 2012

I've overlooked the documentation or it is not supported-stickit does not like optgroups and will remove them from my select elements if they are in there!

Great stuff otherwise!

@ghost
Copy link
Author

ghost commented Nov 15, 2012

Hello!

I forked your wonderful project, and tweaked it so it wouldn't wipe out the optgroup(s). Basically, check if the option already exists before creating it. If the option exists, just perform your actions on the existing one instead of a new one. I'd prefer to use the main repository if possible, so if this fix is implemented I'll revert back to it!

https://github.com/derekhardison/backbone.stickit/commit/62a1f7bcc6e5f5b552dcdf489038ebef559085fe

Derek

@delambo
Copy link
Member

delambo commented Nov 18, 2012

@derekhardison - Another solution might be for stickit to handle another collection data structure. An optgroup could be represented as an ordered hash of labels that map to collections. Since JavaScript doesn't have an ordered hash, an addtional key could be used to map the ordered list of labels. For example:

bindings: {
  modelAttr: 'character',
  'select#tv-characters': {
    collection: function() {
      return {
        'opt_labels': ['Looney Tunes', 'Three Stooges'],
        'Looney Tunes': [{id: 1, name: 'Bugs Bunny'}, {id: 2, name: 'Donald Duck'}],
        'Three Stooges': [{id: 3, name : 'moe'}, {id: 4, name : 'larry'}, {id: 5, name : 'curly'}]
      }
    },
    labelPath: 'name',
    valuePath: 'id'
  }
}

I'm going to sit on this one for a sec. I would love to get some feedback.

@andriijas
Copy link
Contributor

@delambo looks nice.

@ghost
Copy link
Author

ghost commented Nov 27, 2012

@delambo That's fine too, but only allowing it to be built by stickit makes template systems (such as handlebars) less useful if you're setting up simple static lists of options/optgroups. The ability to do it both ways would be nice.

@delambo
Copy link
Member

delambo commented Dec 15, 2012

This is in master. It will go out in the 0.6.1 release, soon.

@derekhardison - one of the major advantages of using stickit is that you don't need to wrestle with template language features or need to write a lot of javascript/configuration in your templates (if any at all - I rarely do!). I find this strategy to be less error prone, easier to configure, and it generally makes developers happier. I'm going to delay support for pre-configured/built lists.

@delambo delambo closed this as completed Dec 15, 2012
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