Browse Source

add maximum selection length option

Zubair 10 years ago
parent
commit
2bdb5dbdae

+ 41 - 2
dist/js/select2.amd.full.js

@@ -2852,6 +2852,36 @@ define('select2/data/maximumInputLength',[
   return MaximumInputLength;
   return MaximumInputLength;
 });
 });
 
 
+define('select2/data/maximumSelectionLength',[
+
+], function (){
+  function MaximumSelectionLength (decorated, $e, options) {
+    this.maximumSelectionLength = options.get('maximumSelectionLength');
+
+    decorated.call(this, $e, options);
+  }
+
+  MaximumSelectionLength.prototype.query =
+    function (decorated, params, callback) {
+
+    var count = this.$element.val() != null ? this.$element.val().length : 0;
+    if (count >= this.maximumSelectionLength) {
+      this.trigger('results:message', {
+        message: 'maximumSelected',
+        args: {
+          maximum: this.maximumSelectionLength
+        }
+      });
+
+      return;
+    }
+
+    decorated.call(this, params, callback);
+  };
+
+  return MaximumSelectionLength;
+});
+
 define('select2/dropdown',[
 define('select2/dropdown',[
   './utils'
   './utils'
 ], function (Utils) {
 ], function (Utils) {
@@ -3403,6 +3433,7 @@ define('select2/defaults',[
   './data/tokenizer',
   './data/tokenizer',
   './data/minimumInputLength',
   './data/minimumInputLength',
   './data/maximumInputLength',
   './data/maximumInputLength',
+  './data/maximumSelectionLength',
 
 
   './dropdown',
   './dropdown',
   './dropdown/search',
   './dropdown/search',
@@ -3421,7 +3452,7 @@ define('select2/defaults',[
              Utils, Translation, DIACRITICS,
              Utils, Translation, DIACRITICS,
 
 
              SelectData, ArrayData, AjaxData, Tags, Tokenizer,
              SelectData, ArrayData, AjaxData, Tags, Tokenizer,
-             MinimumInputLength, MaximumInputLength,
+             MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
 
 
              Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
              Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
              AttachBody, MinimumResultsForSearch, SelectOnClose,
              AttachBody, MinimumResultsForSearch, SelectOnClose,
@@ -3457,6 +3488,13 @@ define('select2/defaults',[
         );
         );
       }
       }
 
 
+      if (options.maximumSelectionLength > 0) {
+        options.dataAdapter = Utils.Decorate(
+          options.dataAdapter,
+          MaximumSelectionLength
+        );
+      }
+
       if (options.tags != null) {
       if (options.tags != null) {
         options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
         options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
       }
       }
@@ -3570,7 +3608,7 @@ define('select2/defaults',[
           language = Translation.loadPath(name);
           language = Translation.loadPath(name);
         } catch (e) {
         } catch (e) {
           // If we couldn't load it, check if it wasn't the full path
           // If we couldn't load it, check if it wasn't the full path
-          name = this.get('amdTranslationBase') + name;
+          name = this.defaults.amdLanguageBase + name;
           language = Translation.loadPath(name);
           language = Translation.loadPath(name);
         }
         }
 
 
@@ -3647,6 +3685,7 @@ define('select2/defaults',[
       matcher: matcher,
       matcher: matcher,
       minimumInputLength: 0,
       minimumInputLength: 0,
       maximumInputLength: 0,
       maximumInputLength: 0,
+      maximumSelectionLength: 0,
       minimumResultsForSearch: 0,
       minimumResultsForSearch: 0,
       selectOnClose: false,
       selectOnClose: false,
       sorter: function (data) {
       sorter: function (data) {

+ 41 - 2
dist/js/select2.amd.js

@@ -2852,6 +2852,36 @@ define('select2/data/maximumInputLength',[
   return MaximumInputLength;
   return MaximumInputLength;
 });
 });
 
 
+define('select2/data/maximumSelectionLength',[
+
+], function (){
+  function MaximumSelectionLength (decorated, $e, options) {
+    this.maximumSelectionLength = options.get('maximumSelectionLength');
+
+    decorated.call(this, $e, options);
+  }
+
+  MaximumSelectionLength.prototype.query =
+    function (decorated, params, callback) {
+
+    var count = this.$element.val() != null ? this.$element.val().length : 0;
+    if (count >= this.maximumSelectionLength) {
+      this.trigger('results:message', {
+        message: 'maximumSelected',
+        args: {
+          maximum: this.maximumSelectionLength
+        }
+      });
+
+      return;
+    }
+
+    decorated.call(this, params, callback);
+  };
+
+  return MaximumSelectionLength;
+});
+
 define('select2/dropdown',[
 define('select2/dropdown',[
   './utils'
   './utils'
 ], function (Utils) {
 ], function (Utils) {
@@ -3403,6 +3433,7 @@ define('select2/defaults',[
   './data/tokenizer',
   './data/tokenizer',
   './data/minimumInputLength',
   './data/minimumInputLength',
   './data/maximumInputLength',
   './data/maximumInputLength',
+  './data/maximumSelectionLength',
 
 
   './dropdown',
   './dropdown',
   './dropdown/search',
   './dropdown/search',
@@ -3421,7 +3452,7 @@ define('select2/defaults',[
              Utils, Translation, DIACRITICS,
              Utils, Translation, DIACRITICS,
 
 
              SelectData, ArrayData, AjaxData, Tags, Tokenizer,
              SelectData, ArrayData, AjaxData, Tags, Tokenizer,
-             MinimumInputLength, MaximumInputLength,
+             MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
 
 
              Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
              Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
              AttachBody, MinimumResultsForSearch, SelectOnClose,
              AttachBody, MinimumResultsForSearch, SelectOnClose,
@@ -3457,6 +3488,13 @@ define('select2/defaults',[
         );
         );
       }
       }
 
 
+      if (options.maximumSelectionLength > 0) {
+        options.dataAdapter = Utils.Decorate(
+          options.dataAdapter,
+          MaximumSelectionLength
+        );
+      }
+
       if (options.tags != null) {
       if (options.tags != null) {
         options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
         options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
       }
       }
@@ -3570,7 +3608,7 @@ define('select2/defaults',[
           language = Translation.loadPath(name);
           language = Translation.loadPath(name);
         } catch (e) {
         } catch (e) {
           // If we couldn't load it, check if it wasn't the full path
           // If we couldn't load it, check if it wasn't the full path
-          name = this.get('amdTranslationBase') + name;
+          name = this.defaults.amdLanguageBase + name;
           language = Translation.loadPath(name);
           language = Translation.loadPath(name);
         }
         }
 
 
@@ -3647,6 +3685,7 @@ define('select2/defaults',[
       matcher: matcher,
       matcher: matcher,
       minimumInputLength: 0,
       minimumInputLength: 0,
       maximumInputLength: 0,
       maximumInputLength: 0,
+      maximumSelectionLength: 0,
       minimumResultsForSearch: 0,
       minimumResultsForSearch: 0,
       selectOnClose: false,
       selectOnClose: false,
       sorter: function (data) {
       sorter: function (data) {

+ 41 - 2
dist/js/select2.full.js

@@ -12387,6 +12387,36 @@ define('select2/data/maximumInputLength',[
   return MaximumInputLength;
   return MaximumInputLength;
 });
 });
 
 
+define('select2/data/maximumSelectionLength',[
+
+], function (){
+  function MaximumSelectionLength (decorated, $e, options) {
+    this.maximumSelectionLength = options.get('maximumSelectionLength');
+
+    decorated.call(this, $e, options);
+  }
+
+  MaximumSelectionLength.prototype.query =
+    function (decorated, params, callback) {
+
+    var count = this.$element.val() != null ? this.$element.val().length : 0;
+    if (count >= this.maximumSelectionLength) {
+      this.trigger('results:message', {
+        message: 'maximumSelected',
+        args: {
+          maximum: this.maximumSelectionLength
+        }
+      });
+
+      return;
+    }
+
+    decorated.call(this, params, callback);
+  };
+
+  return MaximumSelectionLength;
+});
+
 define('select2/dropdown',[
 define('select2/dropdown',[
   './utils'
   './utils'
 ], function (Utils) {
 ], function (Utils) {
@@ -12938,6 +12968,7 @@ define('select2/defaults',[
   './data/tokenizer',
   './data/tokenizer',
   './data/minimumInputLength',
   './data/minimumInputLength',
   './data/maximumInputLength',
   './data/maximumInputLength',
+  './data/maximumSelectionLength',
 
 
   './dropdown',
   './dropdown',
   './dropdown/search',
   './dropdown/search',
@@ -12956,7 +12987,7 @@ define('select2/defaults',[
              Utils, Translation, DIACRITICS,
              Utils, Translation, DIACRITICS,
 
 
              SelectData, ArrayData, AjaxData, Tags, Tokenizer,
              SelectData, ArrayData, AjaxData, Tags, Tokenizer,
-             MinimumInputLength, MaximumInputLength,
+             MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
 
 
              Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
              Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
              AttachBody, MinimumResultsForSearch, SelectOnClose,
              AttachBody, MinimumResultsForSearch, SelectOnClose,
@@ -12992,6 +13023,13 @@ define('select2/defaults',[
         );
         );
       }
       }
 
 
+      if (options.maximumSelectionLength > 0) {
+        options.dataAdapter = Utils.Decorate(
+          options.dataAdapter,
+          MaximumSelectionLength
+        );
+      }
+
       if (options.tags != null) {
       if (options.tags != null) {
         options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
         options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
       }
       }
@@ -13105,7 +13143,7 @@ define('select2/defaults',[
           language = Translation.loadPath(name);
           language = Translation.loadPath(name);
         } catch (e) {
         } catch (e) {
           // If we couldn't load it, check if it wasn't the full path
           // If we couldn't load it, check if it wasn't the full path
-          name = this.get('amdTranslationBase') + name;
+          name = this.defaults.amdLanguageBase + name;
           language = Translation.loadPath(name);
           language = Translation.loadPath(name);
         }
         }
 
 
@@ -13182,6 +13220,7 @@ define('select2/defaults',[
       matcher: matcher,
       matcher: matcher,
       minimumInputLength: 0,
       minimumInputLength: 0,
       maximumInputLength: 0,
       maximumInputLength: 0,
+      maximumSelectionLength: 0,
       minimumResultsForSearch: 0,
       minimumResultsForSearch: 0,
       selectOnClose: false,
       selectOnClose: false,
       sorter: function (data) {
       sorter: function (data) {

File diff suppressed because it is too large
+ 0 - 0
dist/js/select2.full.min.js


+ 41 - 2
dist/js/select2.js

@@ -3280,6 +3280,36 @@ define('select2/data/maximumInputLength',[
   return MaximumInputLength;
   return MaximumInputLength;
 });
 });
 
 
+define('select2/data/maximumSelectionLength',[
+
+], function (){
+  function MaximumSelectionLength (decorated, $e, options) {
+    this.maximumSelectionLength = options.get('maximumSelectionLength');
+
+    decorated.call(this, $e, options);
+  }
+
+  MaximumSelectionLength.prototype.query =
+    function (decorated, params, callback) {
+
+    var count = this.$element.val() != null ? this.$element.val().length : 0;
+    if (count >= this.maximumSelectionLength) {
+      this.trigger('results:message', {
+        message: 'maximumSelected',
+        args: {
+          maximum: this.maximumSelectionLength
+        }
+      });
+
+      return;
+    }
+
+    decorated.call(this, params, callback);
+  };
+
+  return MaximumSelectionLength;
+});
+
 define('select2/dropdown',[
 define('select2/dropdown',[
   './utils'
   './utils'
 ], function (Utils) {
 ], function (Utils) {
@@ -3831,6 +3861,7 @@ define('select2/defaults',[
   './data/tokenizer',
   './data/tokenizer',
   './data/minimumInputLength',
   './data/minimumInputLength',
   './data/maximumInputLength',
   './data/maximumInputLength',
+  './data/maximumSelectionLength',
 
 
   './dropdown',
   './dropdown',
   './dropdown/search',
   './dropdown/search',
@@ -3849,7 +3880,7 @@ define('select2/defaults',[
              Utils, Translation, DIACRITICS,
              Utils, Translation, DIACRITICS,
 
 
              SelectData, ArrayData, AjaxData, Tags, Tokenizer,
              SelectData, ArrayData, AjaxData, Tags, Tokenizer,
-             MinimumInputLength, MaximumInputLength,
+             MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
 
 
              Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
              Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
              AttachBody, MinimumResultsForSearch, SelectOnClose,
              AttachBody, MinimumResultsForSearch, SelectOnClose,
@@ -3885,6 +3916,13 @@ define('select2/defaults',[
         );
         );
       }
       }
 
 
+      if (options.maximumSelectionLength > 0) {
+        options.dataAdapter = Utils.Decorate(
+          options.dataAdapter,
+          MaximumSelectionLength
+        );
+      }
+
       if (options.tags != null) {
       if (options.tags != null) {
         options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
         options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
       }
       }
@@ -3998,7 +4036,7 @@ define('select2/defaults',[
           language = Translation.loadPath(name);
           language = Translation.loadPath(name);
         } catch (e) {
         } catch (e) {
           // If we couldn't load it, check if it wasn't the full path
           // If we couldn't load it, check if it wasn't the full path
-          name = this.get('amdTranslationBase') + name;
+          name = this.defaults.amdLanguageBase + name;
           language = Translation.loadPath(name);
           language = Translation.loadPath(name);
         }
         }
 
 
@@ -4075,6 +4113,7 @@ define('select2/defaults',[
       matcher: matcher,
       matcher: matcher,
       minimumInputLength: 0,
       minimumInputLength: 0,
       maximumInputLength: 0,
       maximumInputLength: 0,
+      maximumSelectionLength: 0,
       minimumResultsForSearch: 0,
       minimumResultsForSearch: 0,
       selectOnClose: false,
       selectOnClose: false,
       sorter: function (data) {
       sorter: function (data) {

File diff suppressed because it is too large
+ 0 - 0
dist/js/select2.min.js


+ 29 - 0
src/js/select2/data/maximumSelectionLength.js

@@ -0,0 +1,29 @@
+define([
+
+], function (){
+  function MaximumSelectionLength (decorated, $e, options) {
+    this.maximumSelectionLength = options.get('maximumSelectionLength');
+
+    decorated.call(this, $e, options);
+  }
+
+  MaximumSelectionLength.prototype.query =
+    function (decorated, params, callback) {
+
+    var count = this.$element.val() != null ? this.$element.val().length : 0;
+    if (count >= this.maximumSelectionLength) {
+      this.trigger('results:message', {
+        message: 'maximumSelected',
+        args: {
+          maximum: this.maximumSelectionLength
+        }
+      });
+
+      return;
+    }
+
+    decorated.call(this, params, callback);
+  };
+
+  return MaximumSelectionLength;
+});

+ 11 - 2
src/js/select2/defaults.js

@@ -20,6 +20,7 @@ define([
   './data/tokenizer',
   './data/tokenizer',
   './data/minimumInputLength',
   './data/minimumInputLength',
   './data/maximumInputLength',
   './data/maximumInputLength',
+  './data/maximumSelectionLength',
 
 
   './dropdown',
   './dropdown',
   './dropdown/search',
   './dropdown/search',
@@ -38,7 +39,7 @@ define([
              Utils, Translation, DIACRITICS,
              Utils, Translation, DIACRITICS,
 
 
              SelectData, ArrayData, AjaxData, Tags, Tokenizer,
              SelectData, ArrayData, AjaxData, Tags, Tokenizer,
-             MinimumInputLength, MaximumInputLength,
+             MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
 
 
              Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
              Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
              AttachBody, MinimumResultsForSearch, SelectOnClose,
              AttachBody, MinimumResultsForSearch, SelectOnClose,
@@ -74,6 +75,13 @@ define([
         );
         );
       }
       }
 
 
+      if (options.maximumSelectionLength > 0) {
+        options.dataAdapter = Utils.Decorate(
+          options.dataAdapter,
+          MaximumSelectionLength
+        );
+      }
+
       if (options.tags != null) {
       if (options.tags != null) {
         options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
         options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
       }
       }
@@ -187,7 +195,7 @@ define([
           language = Translation.loadPath(name);
           language = Translation.loadPath(name);
         } catch (e) {
         } catch (e) {
           // If we couldn't load it, check if it wasn't the full path
           // If we couldn't load it, check if it wasn't the full path
-          name = this.get('amdTranslationBase') + name;
+          name = this.defaults.amdLanguageBase + name;
           language = Translation.loadPath(name);
           language = Translation.loadPath(name);
         }
         }
 
 
@@ -264,6 +272,7 @@ define([
       matcher: matcher,
       matcher: matcher,
       minimumInputLength: 0,
       minimumInputLength: 0,
       maximumInputLength: 0,
       maximumInputLength: 0,
+      maximumSelectionLength: 0,
       minimumResultsForSearch: 0,
       minimumResultsForSearch: 0,
       selectOnClose: false,
       selectOnClose: false,
       sorter: function (data) {
       sorter: function (data) {

Some files were not shown because too many files changed in this diff