Explorar el 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 hace 9 años
padre
commit
68d068f1d2
Se han modificado 1 ficheros con 17 adiciones y 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 () {