Skip to content

Instantly share code, notes, and snippets.

@tomtheisen
Created August 24, 2019 19:30
Show Gist options
  • Save tomtheisen/a77a3257bc3b87f78f1d000e278ca258 to your computer and use it in GitHub Desktop.
Save tomtheisen/a77a3257bc3b87f78f1d000e278ca258 to your computer and use it in GitHub Desktop.
declare var $: any;
function select2EventDispatch(el: HTMLElement, events: string[]) {
let dispatching = false;
$.fn.select2 && $.fn.select2.amd.require(
["select2/utils"], function (Utils: any) {
const instance = Utils.GetData(el, "select2");
instance && events.forEach(ev => {
instance.on(ev, () => {
if (dispatching) return; else dispatching = true;
try { el.dispatchEvent(new Event(ev)); }
finally { dispatching = false; }
});
});
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment