Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do enable hover event on select2 choice

Tags:

jquery

tags

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?

like image 648
Anonymous Avatar asked Feb 03 '26 08:02

Anonymous


1 Answers

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);
   }
   ...
}
like image 148
xtine Avatar answered Feb 05 '26 01:02

xtine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!