1
0
mirror of synced 2024-11-22 21:16:10 +03:00

focus select2 on a click to a related label. fixes #198

This commit is contained in:
Igor Vaynberg 2012-07-20 21:15:11 +03:00
parent 37ff4bbf36
commit 3fc1bc6f35

View File

@ -380,6 +380,8 @@
/**
* blurs any Select2 container that has focus when an element outside them was clicked or received focus
*
* also takes care of clicks on label tags that point to the source element
*/
$(document).ready(function () {
$(document).delegate("*", "mousedown touchend", function (e) {
@ -394,6 +396,13 @@
if (this !== target) $(this).data("select2").blur();
});
}
target=$(e.target);
if ("LABEL" === e.target.tagName && target.attr("for").length > 0) {
target = $("#"+target.attr("for"));
target = target.data("select2");
if (target !== undefined) { target.focus(); e.preventDefault();}
}
});
});