Skip to content

Commit 3063e7b

Browse files
authored
Allow to use function as liveSearchStyle (#2332)
* Allow to use function as liveSearchStyle Fix #2042
1 parent c2c9d71 commit 3063e7b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

docs/docs/options.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap
133133
</tr>
134134
<tr>
135135
<td>liveSearchStyle</td>
136-
<td>string</td>
136+
<td>string | function</td>
137137
<td><code>'contains'</code></td>
138138
<td>
139-
<p>When set to <code>'contains'</code>, searching will reveal options that contain the searched text. For example, searching for pl with return both Ap<b>pl</b>e, <b>Pl</b>um, and <b>Pl</b>antain. When set to <code>'startsWith'</code>, searching for pl will return only <b>Pl</b>um and <b>Pl</b>antain.</p>
139+
<p>When set to <code>'contains'</code>, searching will reveal options that contain the searched text. For example, searching for pl with return both Ap<b>pl</b>e, <b>Pl</b>um, and <b>Pl</b>antain. When set to <code>'startsWith'</code>, searching for pl will return only <b>Pl</b>um and <b>Pl</b>antain. If a function is used, the arguments are the option string and the searched text and it must return <code>true</code> if the option matches or <code>false<code>.</p>
140140
</td>
141141
</tr>
142142
<tr>
@@ -488,4 +488,4 @@ $('#yourSelect').selectpicker({
488488
});
489489
```
490490

491-
For performance reasons, our built-in sanitizer accepts an array of DOM nodes as its first argument, rather than an HTML string. Keep that in mind if deciding to use your own `sanitizeFn`.
491+
For performance reasons, our built-in sanitizer accepts an array of DOM nodes as its first argument, rather than an HTML string. Keep that in mind if deciding to use your own `sanitizeFn`.

js/bootstrap-select.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@
394394
if (normalize) string = normalizeToBase(string);
395395
string = string.toUpperCase();
396396

397-
if (method === 'contains') {
397+
if (typeof method === 'function') {
398+
searchSuccess = method(string, searchString);
399+
} else if (method === 'contains') {
398400
searchSuccess = string.indexOf(searchString) >= 0;
399401
} else {
400402
searchSuccess = string.startsWith(searchString);

0 commit comments

Comments
 (0)