feat: add configurable select2 search threshold; drop autocomplete_enabled on develop

Add the same Select Search Minimum Rows setting added on 1.2.x, wiring it
through as the select2SearchRows JS global (include/global_session.php) and
replacing the hardcoded 10-option cutoff in every select2 initializer in
layout.js.

Remove Autocomplete Enabled entirely on develop: it only ever existed to let
the Classic theme opt out of the ajax-backed callback widgets, and Classic
doesn't exist as a develop theme. html_host_filter() and the Graph Items data
source field now always use the ajax-backed rendering (select2-callback /
drop_callback) unconditionally instead of branching on the removed setting.
This commit is contained in:
TheWitness committed 2026-09-22 10:55:38 -04:00
1 parent 2012c8814d
commit 3cbc5a7566
5 files changed
+57 -87

No files matched your search

+19 -25
View File
@@ -1073,29 +1073,27 @@ function item_edit() : void {
$value = '';
}
if (read_config_option('autocomplete_enabled') > 0) {
$action = 'ajax_graph_items';
$action = 'ajax_graph_items';
if (grv('host_id') > 0) {
$action .= '&host_id=' . gfrv('host_id');
}
if (grv('data_template_id') > 0) {
$action .= '&data_template_id=' . gfrv('data_template_id');
}
$struct_graph_item['task_item_id'] = [
'method' => 'drop_callback',
'friendly_name' => __('Data Source'),
'description' => __('Choose the Data Source to associate with this Graph Item.'),
'sql' => '',
'action' => $action,
'none_value' => __('None'),
'id' => $task_item_id,
'value' => $value
];
if (grv('host_id') > 0) {
$action .= '&host_id=' . gfrv('host_id');
}
if (grv('data_template_id') > 0) {
$action .= '&data_template_id=' . gfrv('data_template_id');
}
$struct_graph_item['task_item_id'] = [
'method' => 'drop_callback',
'friendly_name' => __('Data Source'),
'description' => __('Choose the Data Source to associate with this Graph Item.'),
'sql' => '',
'action' => $action,
'none_value' => __('None'),
'id' => $task_item_id,
'value' => $value
];
// modifications to the default graph items array
$struct_graph_item['task_item_id']['sql'] = "SELECT
CONCAT_WS('', dtd.name_cache,' (', dtr.data_source_name, ')') as name, dtr.id
@@ -1124,11 +1122,7 @@ function item_edit() : void {
foreach ($struct_graph_item as $field_name => $field_array) {
$form_array += [$field_name => $struct_graph_item[$field_name]];
if (read_config_option('autocomplete_enabled')) {
if ($field_name != 'task_item_id') {
$form_array[$field_name]['value'] = (isset($template_item[$field_name]) ? $template_item[$field_name] : '');
}
} else {
if ($field_name != 'task_item_id') {
$form_array[$field_name]['value'] = (isset($template_item[$field_name]) ? $template_item[$field_name] : '');
}
+1
View File
@@ -135,4 +135,5 @@ if ($graphs) {
var sessionNotices=<?php print display_output_messages(); ?>;
var sessionMessage={};
var csrfMagicToken='<?php print csrf_get_tokens(); ?>';
var select2SearchRows=<?php print intval(read_config_option('select2_search_rows')); ?>;
</script>
+10 -6
View File
@@ -1299,14 +1299,18 @@ $settings['visual'] = [
'default' => '30',
'array' => $item_rows
],
'autocomplete_enabled' => [
'friendly_name' => __('Autocomplete Enabled'),
'description' => __('In very large systems, select lists can slow the user interface significantly. If this option is enabled, Cacti will use autocomplete callbacks to populate the select list systematically. Note: autocomplete is forcibly disabled on the Classic theme.'),
'select2_search_rows' => [
'friendly_name' => __('Select Search Minimum Rows'),
'description' => __('The minimum number of options a dropdown must have before Cacti shows a search box inside it. Choose \'Always\' to show the search box regardless of the number of options.'),
'method' => 'drop_array',
'default' => '1',
'default' => '10',
'array' => [
1 => __('Yes'),
0 => __('No')
'0' => __('Always'),
'5' => '5',
'10' => '10',
'15' => '15',
'20' => '20',
'25' => '25'
]
],
'autocomplete_rows' => [
+8 -11
View File
@@ -969,9 +969,8 @@ function applySkin() {
/* Replace icons */
$('.fa-arrow-down').addClass('fa-chevron-down').removeClass('fa-arrow-down');
$('.fa-arrow-up').addClass('fa-chevron-up').removeClass('fa-arrow-up');
$('.fa-remove').addClass('fa-trash-o').removeClass('fa-remove');
if (!theme) {
$var options = {
minimumResultsForSearch: select2SearchRows
theme = 'midwinter';
// debounce submits
@@ -1012,9 +1011,8 @@ function applySkin() {
applyTableSizing();
setupPageTimeout();
CsrfMagic.end();
svar options = {
minimumResultsForSearch: select2SearchRows
setupSpecialKeys();
@@ -1032,7 +1030,7 @@ function applySkin() {
event.stopPropagation();
getCactiHelp($(this).attr('data-page'));
});
select2SearchRows
if (typeof themeReady == 'function') {
themeReady();
}
@@ -1151,10 +1149,9 @@ function applySkin() {
});
return dfd;
});
$('#password').delayKeyup(function () {
var url = window.location.href.split('?')[0] + '?action=checkpass';
}var options = {
width: 'auto',
minimumResultsForSearch: select2SearchRows
checkPassword(url);
});
+19 -45
View File
@@ -2789,8 +2789,6 @@ function html_business_hours_filter(string $callBack = 'applyGraphFilter') : str
* @return void
*/
function html_host_filter(mixed $host_id = -1, string $call_back = 'applyFilter', string $sql_where = '', bool $noany = false, bool $nonone = false) : void {
$theme = get_selected_theme();
if (!str_contains($call_back, '()')) {
$call_back .= '()';
}
@@ -2799,51 +2797,27 @@ function html_host_filter(mixed $host_id = -1, string $call_back = 'applyFilter'
$host_id = gfrv('host_id');
}
if (!read_config_option('autocomplete_enabled')) {
?>
<td>
<?php print __('Device'); ?>
</td>
<td>
<select id='host_id' name='host_id' onChange='<?php print $call_back; ?>' data-defaultLabel='<?php print __('Device'); ?>'>
<?php if (!$noany) {?><option value='-1'<?php if ($host_id == '-1') {?> selected<?php }?>><?php print __('Any'); ?></option><?php }?>
<?php if (!$nonone) {?><option value='0'<?php if ($host_id == '0') {?> selected<?php }?>><?php print __('None'); ?></option><?php }?>
<?php
$devices = get_allowed_devices($sql_where);
if (cacti_sizeof($devices)) {
foreach ($devices as $device) {
print "<option value='{$device['id']}'" . ($host_id == $device['id'] ? ' selected' : '') . '>' . htmle(strip_domain($device['description'])) . '</option>';
}
}
?>
</select>
</td>
<?php
if ($host_id > 0) {
$hostname = db_fetch_cell_prepared('SELECT description
FROM host
WHERE id = ?',
[$host_id]);
} elseif ($host_id == 0) {
$hostname = __('None');
} else {
if ($host_id > 0) {
$hostname = db_fetch_cell_prepared('SELECT description
FROM host
WHERE id = ?',
[$host_id]);
} elseif ($host_id == 0) {
$hostname = __('None');
} else {
$hostname = __('Any');
}
?>
<td>
<?php print __('Device'); ?>
</td>
<td>
<select id='host_id' name='host_id' class='select2-callback' data-action='ajax_hosts' data-variables='site_id' data-callback='<?php print htmle($call_back);?>'>
<option value='<?php print htmle($host_id);?>' selected><?php print htmle($hostname);?></option>
</select>
</td>
<?php
$hostname = __('Any');
}
?>
<td>
<?php print __('Device'); ?>
</td>
<td>
<select id='host_id' name='host_id' class='select2-callback' data-action='ajax_hosts' data-variables='site_id' data-callback='<?php print htmle($call_back);?>'>
<option value='<?php print htmle($host_id);?>' selected><?php print htmle($hostname);?></option>
</select>
</td>
<?php
}
/**