Skip to content

Commit 3fc1bc6

Browse files
committed
focus select2 on a click to a related label. fixes select2#198
1 parent 37ff4bb commit 3fc1bc6

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

select2.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@
380380

381381
/**
382382
* blurs any Select2 container that has focus when an element outside them was clicked or received focus
383+
*
384+
* also takes care of clicks on label tags that point to the source element
383385
*/
384386
$(document).ready(function () {
385387
$(document).delegate("*", "mousedown touchend", function (e) {
@@ -394,6 +396,13 @@
394396
if (this !== target) $(this).data("select2").blur();
395397
});
396398
}
399+
400+
target=$(e.target);
401+
if ("LABEL" === e.target.tagName && target.attr("for").length > 0) {
402+
target = $("#"+target.attr("for"));
403+
target = target.data("select2");
404+
if (target !== undefined) { target.focus(); e.preventDefault();}
405+
}
397406
});
398407
});
399408

0 commit comments

Comments
 (0)