From c84e9fdc44c83d8277d8d5f836c42bd175e68d75 Mon Sep 17 00:00:00 2001 From: nhung-le <64844393+nhung-le@users.noreply.github.com> Date: Thu, 21 Sep 2023 21:42:21 +0700 Subject: [PATCH] Fix ChoiceFieldMaskType inside CollectionType with inline table setting (#8100) --- .../views/Form/form_admin_fields.html.twig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Resources/views/Form/form_admin_fields.html.twig b/src/Resources/views/Form/form_admin_fields.html.twig index 9a98eb885e..4f6ca5c813 100644 --- a/src/Resources/views/Form/form_admin_fields.html.twig +++ b/src/Resources/views/Form/form_admin_fields.html.twig @@ -506,12 +506,24 @@ file that was distributed with this source code. defaultFieldId = '#{{ main_form_name }}_' + field; } + // catch select2 fields with inline: table option + if (jQuery(defaultFieldId).length === 0) { + defaultFieldId = '#{{ main_form_name }}_' + field + '_autocomplete_input'; + } + return defaultFieldId; }; jQuery.each(allFields, function (i, field) { var fieldContainer = controlGroupIdFunc(field); jQuery(fieldContainer).hide(); + {% if form.parent.vars.sonata_admin.inline == 'table' %} + var td = jQuery(fieldContainer).parent(); + var columnIndex = td.index(); + var headerTh = $("table thead tr th:eq(" + columnIndex + ")"); + td.hide(); + headerTh.hide(); + {% endif %} jQuery(fieldContainer).find('[required="required"]').attr('data-required', 'required').removeAttr("required"); }); @@ -519,6 +531,13 @@ file that was distributed with this source code. jQuery.each(map[val], function (i, field) { var fieldContainer = controlGroupIdFunc(field); jQuery(fieldContainer).show(); + {% if form.parent.vars.sonata_admin.inline == 'table' %} + var td = jQuery(fieldContainer).parent(); + var columnIndex = td.index(); + var headerTh = $("table thead tr th:eq(" + columnIndex + ")"); + td.show(); + headerTh.show(); + {% endif %} jQuery(fieldContainer).find('[data-required="required"]').attr("required", "required"); }); }