mxriverlynn / backbone.picky

selectable entities as mixins for Backbone.Model and Backbone.Collection
129 stars 29 forks source link

Added support to configure a limit on how many selections can be made #28

Closed stnor closed 8 months ago

stnor commented 10 years ago

I added support to limit the number of selections that can be made in a MultiSelect. Not sure if this is useful to anyone else, but here goes.

hashchange commented 10 years ago

I have wondered a while ago if there was a use case for a "before:select" event, and couldn't think of anything which would require it. Now here it is.

As an alternative to hard-coding this specific behaviour into Backbone.Picky, a limit could be implemented in an onBeforeSelect event handler. That kind of solution would be a little more flexible. There'd have to be a cancelSelect flag of some kind, which an event handler can set, presumably on an options object which MultiSelect.select has access to. Just a thought.