Skip to content

Instantly share code, notes, and snippets.

@powmedia
Created March 14, 2013 12:49
Show Gist options
  • Save powmedia/5161061 to your computer and use it in GitHub Desktop.
Save powmedia/5161061 to your computer and use it in GitHub Desktop.
/**
* 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);
}
});
@hiddenl00p
Copy link

"Uncaught query function not defined for Select2 " getting this error . i am passing backbone collection as options here is the code avatar:{ type: 'Select2', options: new avatars, title:'Matter' }, and my avatar model has tostring function ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment