Created
November 18, 2015 04:26
-
-
Save RDelorier/5e38f7025cb3883adb64 to your computer and use it in GitHub Desktop.
Notify Vue when chosen select updates
This file contains 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
"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