Settings: fix show_if for selects

This commit is contained in:
slawkens
2026-01-28 21:14:52 +01:00
parent 7916cfa85f
commit 8dcbb66753

View File

@@ -37,21 +37,31 @@
{% for key, value in settings %} {% for key, value in settings %}
{% if value.show_if is defined %} {% if value.show_if is defined %}
$(function () { $(function () {
$('input[name="settings[{{ value.show_if[0] }}]"]').change(function () { {% set inputType = 'input' %}
{% if settings[value.show_if[0]]['type'] == 'options' %}
{% set inputType = 'select' %}
{% endif %}
$('{{ inputType }}[name="settings[{{ value.show_if[0] }}]"]').change(function () {
performChecks_{{ key }}(this); performChecks_{{ key }}(this);
}); });
{% if settings[value.show_if[0]]['type'] == 'boolean' %} {% if settings[value.show_if[0]]['type'] == 'boolean' %}
performChecks_{{ key }}('input[name="settings[{{ value.show_if[0] }}]"]:checked'); performChecks_{{ key }}('input[name="settings[{{ value.show_if[0] }}]"]:checked');
{% else %} {% else %}
performChecks_{{ key }}('input[name="settings[{{ value.show_if[0] }}]"]'); performChecks_{{ key }}('{{ inputType }}[name="settings[{{ value.show_if[0] }}]"]');
{% endif %} {% endif %}
}); });
function performChecks_{{ key }}(el) function performChecks_{{ key }}(el)
{ {
let success = false; let success = false;
let thisVal = $(el).val(); let thisVal = $(el).val();
{% if settings[value.show_if[0]]['type'] == 'options' %}
thisVal = $(el).find(":selected").val();
{% endif %}
let operator = '{{ value.show_if[1]|raw }}'; let operator = '{{ value.show_if[1]|raw }}';
if (operator === '>') { if (operator === '>') {