Skip to content

Instantly share code, notes, and snippets.

@mohitmayank
Created July 10, 2013 18:13
Show Gist options
  • Save mohitmayank/5968696 to your computer and use it in GitHub Desktop.
Save mohitmayank/5968696 to your computer and use it in GitHub Desktop.
backbone-form multi select editor using select2
define([
'underscore',
'backbone',
'backbone-forms',
'form-template',
'select2'
], function (_, Backbone) {
return Backbone.Form.editors.Select.extend({
attributes : {multiple : 'multiple'},
render : function () {
var self = this;
this.setOptions(this.schema.options);
setTimeout(function () {
self.$el.select2({
width : 'resolve'
})
}, 0);
return this;
},
setValue : function (values) {
if (!_.isArray(values)) values = [values];
this.$el.val(values);
},
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment