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

Implement the ability to search with true regexes #2761

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class AbstractChosen
@max_shown_results = @options.max_shown_results || Number.POSITIVE_INFINITY
@case_sensitive_search = @options.case_sensitive_search || false
@hide_results_on_select = if @options.hide_results_on_select? then @options.hide_results_on_select else true
@escape_special_characters = true

set_default_text: ->
if @form_field.getAttribute("data-placeholder")
Expand Down Expand Up @@ -165,7 +166,10 @@ class AbstractChosen
results = 0

searchText = this.get_search_text()
escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
if @escape_special_characters
escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
else
escapedSearchText = searchText
regex = this.get_search_regex(escapedSearchText)
highlightRegex = this.get_highlight_regex(escapedSearchText)

Expand Down
7 changes: 7 additions & 0 deletions public/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ <h3>Example:</h3>
<p>By default Chosen's results are hidden after a option is selected. Setting this option to <code class="language-javascript">false</code> will keep the results open after selection. This only applies to multiple selects.</p>
</td>
</tr>
<tr>
<td>escape_special_characters</td>
<td>true</td>
<td>
<p>By default Chosen's search will escape any special characters. Setting this option to <code class="language-javascript">false</code> will allow the user to entire a javascript regex eg: <code>foo.*bar</code> will now match <code>foobazbar</code></p>
</td>
</tr>
<tr>
<td>rtl</td>
<td>false</td>
Expand Down