Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap
<p>The text displayed when a search doesn't return any results.</p>
</td>
</tr>
<tr>
<td>searchSubtext</td>
<td>boolean</td>
<td><code>true</code></td>
<td>
<p>When set to <code>false</code>, searching will ignore subtext. When set to <code>true</code> searching will include subtext.
</td>
</tr>
<tr>
<td>selectAllText</td>
<td>string</td>
Expand Down
11 changes: 8 additions & 3 deletions js/bootstrap-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,18 @@
};
// </editor-fold>

function stringSearch (li, searchString, method, normalize) {
function stringSearch (li, searchString, method, normalize, searchSubtext) {
var stringTypes = [
'display',
'subtext',
'tokens'
],
searchSuccess = false;

if (!searchSubtext) {
stringTypes.splice(1, 1);
}

for (var i = 0; i < stringTypes.length; i++) {
var stringType = stringTypes[i],
string = li[stringType];
Expand Down Expand Up @@ -971,6 +975,7 @@
liveSearchPlaceholder: null,
liveSearchNormalize: false,
liveSearchStyle: 'contains',
searchSubtext: true,
actionsBox: false,
iconBase: classNames.ICONBASE,
tickIcon: classNames.TICKICON,
Expand Down Expand Up @@ -2982,7 +2987,7 @@
var li = that.selectpicker.main.data[i];

if (!cache[i]) {
cache[i] = stringSearch(li, q, searchStyle, normalizeSearch);
cache[i] = stringSearch(li, q, searchStyle, normalizeSearch, that.options.searchSubtext);
}

if (cache[i] && li.headerIndex !== undefined && cacheArr.indexOf(li.headerIndex) === -1) {
Expand Down Expand Up @@ -3306,7 +3311,7 @@
var li = that.selectpicker.current.data[i],
hasMatch;

hasMatch = stringSearch(li, keyHistory, 'startsWith', true);
hasMatch = stringSearch(li, keyHistory, 'startsWith', true, that.options.searchSubtext);

if (hasMatch && that.selectpicker.view.canHighlight[i]) {
matches.push(li.element);
Expand Down