From b21df4c2c51e30755e7d06778e545e489e4921b9 Mon Sep 17 00:00:00 2001 From: Th0masso <55784802+Th0masso@users.noreply.github.com> Date: Mon, 5 Apr 2021 03:06:49 +0200 Subject: [PATCH 1/3] Add-max-displayable-elements --- src/jquery.bootstrap-duallistbox.js | 32 ++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/jquery.bootstrap-duallistbox.js b/src/jquery.bootstrap-duallistbox.js index 93e0423..dd48d0a 100644 --- a/src/jquery.bootstrap-duallistbox.js +++ b/src/jquery.bootstrap-duallistbox.js @@ -50,7 +50,9 @@ btnMoveText: '>', // string, sets the text for the "Move" button btnRemoveText: '<', // string, sets the text for the "Remove" button btnMoveAllText: '>>', // string, sets the text for the "Move All" button - btnRemoveAllText: '<<' // string, sets the text for the "Remove All" button + btnRemoveAllText: '<<', // string, sets the text for the "Remove All" button + maxElements: 500, // int, sets the maximum element in a list + maxElementsText: "Maximum number of displayable elements reached" // string, sets text for the disabled option that indicates that the maximum number of displayable elements have been reached }, // Selections are invisible on android if the containing select is styled with CSS // http://code.google.com/p/android/issues/detail?id=16922 @@ -189,12 +191,20 @@ regex = new RegExp('/a^/', 'gi'); } + var maxSelectedReached = false; + var elements = 0; options.each(function(index, item) { + elements++; var $item = $(item), isFiltered = true; if (item.text.match(regex) || (dualListbox.settings.filterOnValues && $item.attr('value').match(regex) ) ) { isFiltered = false; - dualListbox.elements['select'+selectIndex].append($item.clone(true).prop('selected', $item.data('_selected'))); + if (elements < dualListbox.settings.maxElements) { + dualListbox.elements['select'+selectIndex].append($item.clone(true).prop('selected', $item.data('_selected'))); + } else if (!maxSelectedReached) { + maxSelectedReached = true; + dualListbox.elements.select1.append(''); + } } allOptions.eq($item.data('original-index')).data('filtered'+selectIndex, isFiltered); }); @@ -490,6 +500,8 @@ this.setBtnRemoveText(this.settings.btnRemoveText); this.setBtnMoveAllText(this.settings.btnMoveAllText); this.setBtnRemoveAllText(this.settings.btnRemoveAllText); + this.setMaxElements(this.settings.maxElements); + this.setMaxElementsText(this.settings.maxElementsText); // Hide the original select this.element.hide(); @@ -781,6 +793,13 @@ } return this.element; }, + setMaxElements: function(value, refresh) { + this.settings.maxElements = value; + if (refresh) { + refreshSelects(this); + } + return this.element; + }, setBtnMoveText: function(value, refresh) { this.settings.btnMoveText = value; this.elements.moveButton.html(value); @@ -813,6 +832,13 @@ } return this.element; }, + setMaxElementsText: function(value, refresh) { + this.settings.maxElementsText = value; + if (refresh) { + refreshSelects(this); + } + return this.element; + }, getContainer: function() { return this.container; }, @@ -881,4 +907,4 @@ }; -})); +})); \ No newline at end of file From fc3f9094f7200cacb8a4370acf99464a559326e9 Mon Sep 17 00:00:00 2001 From: Th0masso <55784802+Th0masso@users.noreply.github.com> Date: Mon, 5 Apr 2021 03:11:27 +0200 Subject: [PATCH 2/3] typo --- src/jquery.bootstrap-duallistbox.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jquery.bootstrap-duallistbox.js b/src/jquery.bootstrap-duallistbox.js index dd48d0a..c7f6c43 100644 --- a/src/jquery.bootstrap-duallistbox.js +++ b/src/jquery.bootstrap-duallistbox.js @@ -51,8 +51,8 @@ btnRemoveText: '<', // string, sets the text for the "Remove" button btnMoveAllText: '>>', // string, sets the text for the "Move All" button btnRemoveAllText: '<<', // string, sets the text for the "Remove All" button - maxElements: 500, // int, sets the maximum element in a list - maxElementsText: "Maximum number of displayable elements reached" // string, sets text for the disabled option that indicates that the maximum number of displayable elements have been reached + maxElements: 500, // int, sets the maximum number of displayable elements in a select + maxElementsText: "Maximum number of displayable elements reached" // string, sets text for the disabled option that indicates that the maximum number of displayable elements have been reached }, // Selections are invisible on android if the containing select is styled with CSS // http://code.google.com/p/android/issues/detail?id=16922 From 6c3dee37c7bfca675fc1eaabd666912efff48e43 Mon Sep 17 00:00:00 2001 From: Th0masso <55784802+Th0masso@users.noreply.github.com> Date: Mon, 5 Apr 2021 15:38:56 +0200 Subject: [PATCH 3/3] fix double quote typo --- src/jquery.bootstrap-duallistbox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery.bootstrap-duallistbox.js b/src/jquery.bootstrap-duallistbox.js index c7f6c43..6f1be97 100644 --- a/src/jquery.bootstrap-duallistbox.js +++ b/src/jquery.bootstrap-duallistbox.js @@ -52,7 +52,7 @@ btnMoveAllText: '>>', // string, sets the text for the "Move All" button btnRemoveAllText: '<<', // string, sets the text for the "Remove All" button maxElements: 500, // int, sets the maximum number of displayable elements in a select - maxElementsText: "Maximum number of displayable elements reached" // string, sets text for the disabled option that indicates that the maximum number of displayable elements have been reached + maxElementsText: 'Maximum number of displayable elements reached' // string, sets text for the disabled option that indicates that the maximum number of displayable elements have been reached }, // Selections are invisible on android if the containing select is styled with CSS // http://code.google.com/p/android/issues/detail?id=16922