From f67cde8b28d42b5a112f7bd507f87a898d7b1612 Mon Sep 17 00:00:00 2001 From: David Stone Date: Tue, 24 Mar 2026 16:02:43 -0600 Subject: [PATCH] fix: settings search navigation and title-based search (#311) - Replace item_add handler in selectizer.js to use selectize.options[value] instead of iterating a custom savedItems array with a hardcoded 'setting_id' comparison. The options store is always populated when an item is added, making navigation reliable regardless of AJAX timing. - Update search_wp_ultimo_setting() in class-ajax.php to search across setting_id, title, and desc fields (case-insensitive) instead of only setting_id. Users can now find settings by typing human-readable names like 'Company Name' rather than internal keys like 'company_name'. - Update selectizer.min.js with equivalent minified change. --- assets/js/selectizer.js | 26 ++++++++++------------- assets/js/selectizer.min.js | 2 +- inc/class-ajax.php | 42 ++++++++++++++++++++++++++++++------- 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/assets/js/selectizer.js b/assets/js/selectizer.js index edce18839..01ebeb220 100644 --- a/assets/js/selectizer.js +++ b/assets/js/selectizer.js @@ -172,21 +172,17 @@ selectize.on('item_add', function(value) { - let active_item = { - url: null, - }; - - jQuery.each(selectize.savedItems, function(index, item) { - - if (item.setting_id === value) { - - active_item = item; - - } // end if; - - }); - - if (active_item.url) { + /* + * Look up the selected item directly from selectize's options store, + * which is keyed by the valueField and is always populated when an + * item is added. This replaces the previous approach of searching + * through a custom savedItems array with a hardcoded 'setting_id' + * field comparison, which failed when savedItems was not yet populated + * or when the valueField differed from 'setting_id'. + */ + const active_item = selectize.options[ value ]; + + if (active_item && active_item.url) { window.location.href = active_item.url; diff --git a/assets/js/selectizer.min.js b/assets/js/selectizer.min.js index 09034b0de..7511383d1 100644 --- a/assets/js/selectizer.min.js +++ b/assets/js/selectizer.min.js @@ -1 +1 @@ -(i=>{i(document).ready(function(){window.wu_initialize_selectizer=function(){i.each(i("[data-selectize]"),function(e,t){var t=jQuery(i(t)),a=t.find("option").length,l={};1e3{i(document).ready(function(){window.wu_initialize_selectizer=function(){i.each(i("[data-selectize]"),function(e,t){var t=jQuery(i(t)),a=t.find("option").length,l={};1e3 'title', - 'where' => [ - ['setting_id', '~', trim((string) $query['search'], '*')], - ['type', '!=', 'header'], - ], - ] + function ($item) use ($search_term) { + + if (wu_get_isset($item, 'type') === 'header') { + return false; + } + + $setting_id = strtolower((string) wu_get_isset($item, 'setting_id', '')); + $title = strtolower((string) wu_get_isset($item, 'title', '')); + $desc = strtolower((string) wu_get_isset($item, 'desc', '')); + + return str_contains($setting_id, $search_term) + || str_contains($title, $search_term) + || str_contains($desc, $search_term); + } + ); + + usort( + $_settings, + function ($a, $b) { + + return strcmp( + (string) wu_get_isset($a, 'title', ''), + (string) wu_get_isset($b, 'title', '') + ); + } ); return array_values($_settings);