Skip to content

Instantly share code, notes, and snippets.

@RDelorier
Created November 18, 2015 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RDelorier/5e38f7025cb3883adb64 to your computer and use it in GitHub Desktop.
Save RDelorier/5e38f7025cb3883adb64 to your computer and use it in GitHub Desktop.
Notify Vue when chosen select updates
"use strict";
import Vue from 'vue';
Vue.directive('chosen', {
bind(){
var event = document.createEvent('HTMLEvents');
event.initEvent('change', true, true);
$(this.el).chosen({
width:'100%'
}).change(e => {
//fire true update event for vue,
if(e.originalEvent !== event){
this.el.dispatchEvent(event);
}
});
},
//update chosen when dom updates
update(){
$(this.el).trigger('chosen:updated');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment