- last update
over 1 year ago 17 pass - 🇧🇪Belgium DuneBL
This patch is nice and working well except if we are adding fields in an empty group in the hook
form_alter
.
I am using the following function to add $form[$field_name] to a group (id=$group_name):function addToGroup(array &$form, string $field_name, string $group_name) { /** @var EntityFormDisplay $form_display */ $form_display = $form['#process'][1][0]; $form[$field_name]['#group'] = $group_name; $field_group = $form_display->getThirdPartySettings('field_group')[$group_name]; $field_group['children'][] = $field_name; $form_display->setThirdPartySetting('field_group', $group_name, $field_group); } }
If I add $form['field_to_add'] in a group which is empty but which have the option "
Display element also when empty
" checked; then the group is not displayed.To summarize, there are 2 issues:
1-The patch doesn't take into account the optionDisplay element also when empty
2-The patch doesn't take into account any element added to the group in theform_alter
hook - 🇫🇷France prudloff Lille
The patch works correcly on initial load, but it does not seems to work correctly when detecting a change.
We have a fieldset containing 3 fields that can be shown/hidden depending on when another checkbox field is checked (we use conditional_fields for this).
The field group is initially hidden but if I make the fields visible then hide them, the field group is not hidden and is displayed empty.This seems to happen because when
Drupal.FieldGroup.hideGroupIfEmpty()
evaluate thedisplay
property of the fields, the last does not havenone
yet. So it might be some kind of race condition that makes it check the field too soon.
If I do something like this, then it works correctly:diff --git a/formatters/fieldset/fieldset.js b/formatters/fieldset/fieldset.js index 7349be4..3a2f052 100644 --- a/formatters/fieldset/fieldset.js +++ b/formatters/fieldset/fieldset.js @@ -34,7 +34,9 @@ if ($(e.target).hasClass('field-group-child-field')) { let $group = $(e.target).closest('.field-group-fieldset'); if ($group.length !== 0) { - Drupal.FieldGroup.hideGroupIfEmpty($group, null, true); + setTimeout(function () { + Drupal.FieldGroup.hideGroupIfEmpty($group, null, true); + }, 500); } } });
(This is obviously not the way to the fix the problem, but it helps demonstrate it.)
- Status changed to Needs work
about 1 month ago 9:43am 21 November 2024 - 🇧🇷Brazil karen-kramek
Hello everyone,
Re-holl of patch field_group-2978747-40.patch (8.x-3.0), now covering the module version 8.x-3.6.