소스 검색

Check that `allowClear` is used with `placeholder`

The `allowClear` option may not work as intended if a placeholder
is not used. This is becaise the placeholder holds the value that
the `<select>` should be reset to when the `x` is hit.

An error is now properly raised in the console when Select2 detects
that the `allowClear` option is used without the `placeholder`
option.

This closes https://github.com/select2/select2/issues/3016.
Kevin Brown 10 년 전
부모
커밋
78b6faf13e
8개의 변경된 파일75개의 추가작업 그리고 30개의 파일을 삭제
  1. 15 6
      dist/js/select2.amd.full.js
  2. 15 6
      dist/js/select2.amd.js
  3. 15 6
      dist/js/select2.full.js
  4. 0 0
      dist/js/select2.full.min.js
  5. 15 6
      dist/js/select2.js
  6. 0 0
      dist/js/select2.min.js
  7. 6 6
      src/js/select2/defaults.js
  8. 9 0
      src/js/select2/selection/allowClear.js

+ 15 - 6
dist/js/select2.amd.full.js

@@ -1142,6 +1142,15 @@ define('select2/selection/allowClear',[
 
     decorated.call(this, container, $container);
 
+    if (self.placeholder == null) {
+      if (console && console.error) {
+        console.error(
+          'Select2: The `allowClear` option should be used in combination ' +
+          'with the `placeholder` option.'
+        );
+      }
+    }
+
     this.$selection.on('mousedown', '.select2-selection__clear',
       function (evt) {
         // Ignore the event if it is disabled
@@ -3796,13 +3805,13 @@ define('select2/defaults',[
           options.selectionAdapter,
           Placeholder
         );
+      }
 
-        if (options.allowClear) {
-          options.selectionAdapter = Utils.Decorate(
-            options.selectionAdapter,
-            AllowClear
-          );
-        }
+      if (options.allowClear) {
+        options.selectionAdapter = Utils.Decorate(
+          options.selectionAdapter,
+          AllowClear
+        );
       }
 
       if (options.multiple) {

+ 15 - 6
dist/js/select2.amd.js

@@ -1142,6 +1142,15 @@ define('select2/selection/allowClear',[
 
     decorated.call(this, container, $container);
 
+    if (self.placeholder == null) {
+      if (console && console.error) {
+        console.error(
+          'Select2: The `allowClear` option should be used in combination ' +
+          'with the `placeholder` option.'
+        );
+      }
+    }
+
     this.$selection.on('mousedown', '.select2-selection__clear',
       function (evt) {
         // Ignore the event if it is disabled
@@ -3796,13 +3805,13 @@ define('select2/defaults',[
           options.selectionAdapter,
           Placeholder
         );
+      }
 
-        if (options.allowClear) {
-          options.selectionAdapter = Utils.Decorate(
-            options.selectionAdapter,
-            AllowClear
-          );
-        }
+      if (options.allowClear) {
+        options.selectionAdapter = Utils.Decorate(
+          options.selectionAdapter,
+          AllowClear
+        );
       }
 
       if (options.multiple) {

+ 15 - 6
dist/js/select2.full.js

@@ -1580,6 +1580,15 @@ define('select2/selection/allowClear',[
 
     decorated.call(this, container, $container);
 
+    if (self.placeholder == null) {
+      if (console && console.error) {
+        console.error(
+          'Select2: The `allowClear` option should be used in combination ' +
+          'with the `placeholder` option.'
+        );
+      }
+    }
+
     this.$selection.on('mousedown', '.select2-selection__clear',
       function (evt) {
         // Ignore the event if it is disabled
@@ -4234,13 +4243,13 @@ define('select2/defaults',[
           options.selectionAdapter,
           Placeholder
         );
+      }
 
-        if (options.allowClear) {
-          options.selectionAdapter = Utils.Decorate(
-            options.selectionAdapter,
-            AllowClear
-          );
-        }
+      if (options.allowClear) {
+        options.selectionAdapter = Utils.Decorate(
+          options.selectionAdapter,
+          AllowClear
+        );
       }
 
       if (options.multiple) {

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
dist/js/select2.full.min.js


+ 15 - 6
dist/js/select2.js

@@ -1580,6 +1580,15 @@ define('select2/selection/allowClear',[
 
     decorated.call(this, container, $container);
 
+    if (self.placeholder == null) {
+      if (console && console.error) {
+        console.error(
+          'Select2: The `allowClear` option should be used in combination ' +
+          'with the `placeholder` option.'
+        );
+      }
+    }
+
     this.$selection.on('mousedown', '.select2-selection__clear',
       function (evt) {
         // Ignore the event if it is disabled
@@ -4234,13 +4243,13 @@ define('select2/defaults',[
           options.selectionAdapter,
           Placeholder
         );
+      }
 
-        if (options.allowClear) {
-          options.selectionAdapter = Utils.Decorate(
-            options.selectionAdapter,
-            AllowClear
-          );
-        }
+      if (options.allowClear) {
+        options.selectionAdapter = Utils.Decorate(
+          options.selectionAdapter,
+          AllowClear
+        );
       }
 
       if (options.multiple) {

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
dist/js/select2.min.js


+ 6 - 6
src/js/select2/defaults.js

@@ -172,13 +172,13 @@ define([
           options.selectionAdapter,
           Placeholder
         );
+      }
 
-        if (options.allowClear) {
-          options.selectionAdapter = Utils.Decorate(
-            options.selectionAdapter,
-            AllowClear
-          );
-        }
+      if (options.allowClear) {
+        options.selectionAdapter = Utils.Decorate(
+          options.selectionAdapter,
+          AllowClear
+        );
       }
 
       if (options.multiple) {

+ 9 - 0
src/js/select2/selection/allowClear.js

@@ -8,6 +8,15 @@ define([
 
     decorated.call(this, container, $container);
 
+    if (self.placeholder == null) {
+      if (console && console.error) {
+        console.error(
+          'Select2: The `allowClear` option should be used in combination ' +
+          'with the `placeholder` option.'
+        );
+      }
+    }
+
     this.$selection.on('mousedown', '.select2-selection__clear',
       function (evt) {
         // Ignore the event if it is disabled

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.