Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Last active July 6, 2016 11:19
Show Gist options
  • Save james2doyle/85e503c77e581df6a5c0 to your computer and use it in GitHub Desktop.
Save james2doyle/85e503c77e581df6a5c0 to your computer and use it in GitHub Desktop.
Selectize dropdown and tags directives for Vue.js
// usage: v-selectize-dropdown="dataKeyToBindTo"
Vue.directive('selectize-dropdown', {
twoWay: true,
priority: 1000,
bind: function () {
var self = this;
$(this.el).selectize({
create: true,
sortField: 'text',
onChange: function (val) {
self.set(val);
}
});
},
update: function (value) {
$(this.el).val(value).trigger('change');
},
unbind: function () {
$(this.el).destroy();
}
});
// usage: v-selectize-tags="dataKeyToBindTo"
Vue.directive('selectize-tags', {
twoWay: true,
priority: 1000,
bind: function () {
var self = this;
$(this.el).selectize({
delimiter: ',',
persist: false,
create: function(input) {
return {
value: input,
text: input
};
},
onChange: function (val) {
self.set(val);
}
});
},
update: function (value) {
$(this.el).val(value).trigger('change');
},
unbind: function () {
$(this.el).destroy();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment