Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add-max-displayable-elements #181

Open
wants to merge 3 commits into
base: v4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 29 additions & 3 deletions src/jquery.bootstrap-duallistbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand Down Expand Up @@ -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('<option disabled>' + dualListbox.settings.maxElementsText + '</option>');
}
}
allOptions.eq($item.data('original-index')).data('filtered'+selectIndex, isFiltered);
});
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
},
Expand Down Expand Up @@ -881,4 +907,4 @@

};

}));
}));