Skip to content

Instantly share code, notes, and snippets.

@bogn
Forked from powmedia/gist:5161061
Last active December 21, 2015 10:28
Show Gist options
  • Save bogn/6291691 to your computer and use it in GitHub Desktop.
Save bogn/6291691 to your computer and use it in GitHub Desktop.
Select2
/**
* Select2
*
* Renders Select2 - jQuery based replacement for select boxes
*
* Simply pass a 'config' object on your schema, with any options to pass into Select2.
* See http://ivaynberg.github.com/select2/#documentation
*/
Backbone.Form.editors.Select2 = Backbone.Form.editors.Base.extend({
/**
* @param {Object} options.schema.config Options to pass to select2. See http://ivaynberg.github.com/select2/#documentation
*/
initialize: function(options) {
Backbone.Form.editors.Base.prototype.initialize.call(this, options);
var schema = this.schema;
this.config = schema.config || {};
},
render: function() {
var self = this;
setTimeout(function() {
self.$el.select2(self.config);
}, 0);
return this;
},
getValue: function() {
return this.$el.val();
},
setValue: function(val) {
this.$el.val(val);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment