Fixed elements field to properly allow unlimited combinations

This commit is contained in:
Djamil Legato
2022-01-10 11:01:38 -08:00
parent a1e4e5979e
commit c58c7aebb9
4 changed files with 8850 additions and 107586 deletions

View File

@@ -1,13 +1,10 @@
import $ from 'jquery';
const enabled = '_enabled';
const disabled = '_disabled';
$(document).on('change', '[data-grav-elements] select', (event) => {
const target = $(event.currentTarget);
const value = target.val() === '1';
const value = target.val();
const id = target.closest('[data-grav-elements]').data('gravElements');
$(`[id="${id}_${enabled}"]`).css('display', value ? 'inherit' : 'none');
$(`[id="${id}_${disabled}"]`).css('display', !value ? 'inherit' : 'none');
$(`[id^="${id}_"]`).css('display', 'none');
$(`[id="${id}__${value}"]`).css('display', 'inherit');
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -2,9 +2,9 @@
{% block field %}
{% embed 'forms/default/fields.html.twig' with {name: field.name, fields: field.fields} %}
{% set initial_state = (field.name == 'enabled' and parent_value) or (field.name == 'disabled' and not parent_value) ? '' : 'display: none;' %}
{% set initial_state = field.name == parent_value ? '' : 'display: none;' %}
{% block outer_markup_field_open %}
<div id="{{ parent_name ~ '__' ~ field.name }}" class="form-element" style="{{ initial_state }}">
<div id="{{ parent_name ~ '__' ~ field.name }}" class="form-element" style="{{ initial_state }}">
{% endblock %}
{% block outer_markup_field_close %}