Explorar o código

Prevent selections from being removed when disabled

This prevents selections from being removed when the container is
disabled. This stops any click events that are triggered on the
remove button, so the remove handler won't be triggered at all.

This closes https://github.com/select2/select2/pull/3636.
Kevin Brown %!s(int64=9) %!d(string=hai) anos
pai
achega
68d068f1d2
Modificáronse 1 ficheiros con 17 adicións e 9 borrados
  1. 17 9
      src/js/select2/selection/multiple.js

+ 17 - 9
src/js/select2/selection/multiple.js

@@ -32,18 +32,26 @@ define([
       });
     });
 
-    this.$selection.on('click', '.select2-selection__choice__remove',
+    this.$selection.on(
+      'click',
+      '.select2-selection__choice__remove',
       function (evt) {
-      var $remove = $(this);
-      var $selection = $remove.parent();
+        // Ignore the event if it is disabled
+        if (self.options.get('disabled')) {
+          return;
+        }
 
-      var data = $selection.data('data');
+        var $remove = $(this);
+        var $selection = $remove.parent();
 
-      self.trigger('unselect', {
-        originalEvent: evt,
-        data: data
-      });
-    });
+        var data = $selection.data('data');
+
+        self.trigger('unselect', {
+          originalEvent: evt,
+          data: data
+        });
+      }
+    );
   };
 
   MultipleSelection.prototype.clear = function () {