Last active
July 6, 2016 11:19
-
-
Save james2doyle/85e503c77e581df6a5c0 to your computer and use it in GitHub Desktop.
Selectize dropdown and tags directives for Vue.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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