Browse Source

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

Igor Vaynberg 13 năm trước cách đây
mục cha
commit
3fc1bc6f35
1 tập tin đã thay đổi với 9 bổ sung0 xóa
  1. 9 0
      select2.js

+ 9 - 0
select2.js

@@ -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();}
+            }
         });
     });