for (const element of document.querySelectorAll('#units, #units_pos, #units_size, #units_bold, #units_color')) {
<?php declare(strict_types = 0);
window.widget_item_form = new class {
init({thresholds_colors}) {
this._form = document.getElementById('widget-dialogue-form');
this._show_description = document.getElementById(`show_${<?= Widget::SHOW_DESCRIPTION ?>}`);
this._show_value = document.getElementById(`show_${<?= Widget::SHOW_VALUE ?>}`);
this._show_time = document.getElementById(`show_${<?= Widget::SHOW_TIME ?>}`);
this._show_change_indicator = document.getElementById(`show_${<?= Widget::SHOW_CHANGE_INDICATOR ?>}`);
this._units_show = document.getElementById('units_show');
jQuery('#itemid').on('change', () => {
if (this._form.isConnected) {
for (const colorpicker of this._form.querySelectorAll('.<?= ZBX_STYLE_COLOR_PICKER ?> input')) {
$(colorpicker).colorpicker({
appendTo: ".overlay-dialogue-body",
use_default: !colorpicker.name.includes('thresholds'),
onUpdate: ['up_color', 'down_color', 'updown_color'].includes(colorpicker.name)
? (color) => this.setIndicatorColor(colorpicker.name, color)
const show = [this._show_description, this._show_value, this._show_time, this._show_change_indicator];
for (const checkbox of show) {
checkbox.addEventListener('change', () => this.updateForm());
document.getElementById('units_show').addEventListener('change', () => this.updateForm());
document.getElementById('aggregate_function').addEventListener('change', () => this.updateForm());
document.getElementById('history').addEventListener('change', () => this.updateForm());
colorPalette.setThemeColors(thresholds_colors);
if (this._form.isConnected) {
const aggregate_function = document.getElementById('aggregate_function');
for (const element of this._form.querySelectorAll('.fields-group-description')) {
element.style.display = this._show_description.checked ? '' : 'none';
for (const input of element.querySelectorAll('input, textarea')) {
input.disabled = !this._show_description.checked;
for (const element of this._form.querySelectorAll('.fields-group-value')) {
element.style.display = this._show_value.checked ? '' : 'none';