From 18f8577005bba7dae921090ae18534a663612300 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 31 Mar 2023 14:02:09 -0500 Subject: [PATCH] Improve global menu search behavior for multiple terms --- tailbone/templates/base.mako | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tailbone/templates/base.mako b/tailbone/templates/base.mako index f4935113..df4451c6 100644 --- a/tailbone/templates/base.mako +++ b/tailbone/templates/base.mako @@ -757,8 +757,27 @@ if (!this.globalSearchTerm.length) { return this.globalSearchData } + + let terms = [] + for (let term of this.globalSearchTerm.toLowerCase().split(' ')) { + term = term.trim() + if (term) { + terms.push(term) + } + } + if (!terms.length) { + return this.globalSearchData + } + + // all terms must match return this.globalSearchData.filter((option) => { - return option.label.toLowerCase().indexOf(this.globalSearchTerm.toLowerCase()) >= 0 + let label = option.label.toLowerCase() + for (let term of terms) { + if (label.indexOf(term) < 0) { + return false + } + } + return true }) },