I'm using select2. The build-in event does not support hover event on choiced item, therefore I'm trying to fire hover event when mouse over the item (multiple selection).
function tagFormat(state) {
return '<span class="tagElement">' + state.text + '</span>';
}
$('.tagElement').hover(function(event){
alert('something');
});
var sampleTags = ['red','white'];
$("[taggable]").select2({
formatSelection: tagFormat,
maximumInputLength: 10,
tags:sampleTags,
tokenSeparators: [",", " "]
});
Bootply at http://bootply.com/96527 , you can see that outside select2 the hover event does fire however inside select2 it doesn't. What's the mechanism inside?
select2.js has a function, .show, which updates the attribute "aria-describedby" whenever you hover over an option. This function can be extended...
jsfiddle example
c.prototype.show = function() {
var b = a.Event("show.bs." + this.type);
this.$element.trigger(b);
var d = a.contains(this.$element[0].ownerDocument.documentElement, this.$element[0]);
if (b.isDefaultPrevented() || !d) return;
var e = this,
f = this.tip(),
g = this.getUID(this.type);
/*look for the select box and find the 'onmouseover' attribute */
var s = this.$element.siblings('select');
if (s != undefined && s.attr('onmouseover') != undefined) {
var m = s.attr('onmouseover');
eval(m);
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With