Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions assets/js/selectizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion assets/js/selectizer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 34 additions & 8 deletions inc/class-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,41 @@ function ($item) use ($section, $section_slug) {
$all_fields = array_merge($all_fields, $section['fields']);
}

$_settings = \Arrch\Arrch::find(
$search_term = strtolower(trim((string) $query['search'], '*'));

/*
* Filter settings that match the search term against setting_id, title,
* or desc fields (case-insensitive), excluding header-type fields.
* The previous implementation only searched setting_id, which meant users
* could not find settings by their human-readable titles.
*/
$_settings = array_filter(
$all_fields,
[
'sort_key' => '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);
Expand Down
Loading