diff --git a/plugin/src/main/java/com/arcbees/chosen/client/ChosenOptions.java b/plugin/src/main/java/com/arcbees/chosen/client/ChosenOptions.java index e7d66a9..b49581f 100644 --- a/plugin/src/main/java/com/arcbees/chosen/client/ChosenOptions.java +++ b/plugin/src/main/java/com/arcbees/chosen/client/ChosenOptions.java @@ -31,6 +31,7 @@ public class ChosenOptions { private boolean searchContains; private boolean singleBackstrokeDelete; private boolean highlightSearchTerm; + private boolean performSearchIfEmptyText; private ResultsFilter resultFilter; private DropdownPosition dropdownPosition; private Element dropdownBoundaries; @@ -266,6 +267,15 @@ public boolean isSingleBackstrokeDelete() { return singleBackstrokeDelete; } + public ChosenOptions setPerformSearchIfEmptyText(boolean performSearchIfEmptyText) { + this.performSearchIfEmptyText = performSearchIfEmptyText; + return this; + } + + public boolean isPerformSearchIfEmptyText() { + return performSearchIfEmptyText; + } + public ChosenOptions setSingleBackstrokeDelete(boolean singleBackstrokeDelete) { this.singleBackstrokeDelete = singleBackstrokeDelete; return this; @@ -297,6 +307,7 @@ private void setDefault() { maxSelectedOptions = -1; highlightSearchTerm = true; dropdownPosition = DropdownPosition.BELOW; + performSearchIfEmptyText = true; mobileViewportMaxWidth = 649; oneSelectedTextMultipleMobile = "{} item selected"; manySelectedTextMultipleMobile = "{} items selected"; diff --git a/plugin/src/main/java/com/arcbees/chosen/client/ClientResultsFilter.java b/plugin/src/main/java/com/arcbees/chosen/client/ClientResultsFilter.java index 5f41f78..7d152d0 100644 --- a/plugin/src/main/java/com/arcbees/chosen/client/ClientResultsFilter.java +++ b/plugin/src/main/java/com/arcbees/chosen/client/ClientResultsFilter.java @@ -40,6 +40,11 @@ public void filter(String searchText, ChosenImpl chosen, boolean isShowing) { RegExp regex = RegExp.compile(regexAnchor + escapedSearchText, "i"); RegExp zregex = RegExp.compile("(" + escapedSearchText + ")", "i"); + boolean performSearch = true; + if (!options.isPerformSearchIfEmptyText() && searchText.isEmpty()) { + performSearch = false; + } + int results = 0; List selectItems = chosen.getSelectItems(); @@ -63,13 +68,13 @@ public void filter(String searchText, ChosenImpl chosen, boolean isShowing) { optionContent = option.getText(); } - if (regex.test(optionContent)) { + if (performSearch && regex.test(optionContent)) { found = true; results++; } else if (optionContent.contains(" ") || optionContent.indexOf("[") == 0) { String[] parts = optionContent.replaceAll("\\[|\\]", "").split(" "); for (String part : parts) { - if (regex.test(part)) { + if (performSearch && regex.test(part)) { found = true; results++; }