How to group webform elements (only) visually

Created on 10 April 2025, 3 days ago

Problem

In my webforms, I would like to (visually) group certain elements for my visitors:

I've successfully managed to build this using container elements (sections) in the Drupal webform backend ui.

However, I notice that wehn I move webform elements into one of my container elements, some of my custom code no longer works. These elements are now sub-elements and end up somewhere else in the $form array. For example, code that targets the 'name' field simply no longer works after I add it to the 'personal' section.

Question

Is there any way to group elements strictly visually (i.e. without any consequences for the array and my custom code)?

P.S.
The only possibility I can think of is to create a twig template (webform--MYFORM.html.twig) where I render every element separately so I can group them with custom HTML, but that practically renders the webform ui builder useless, as I have to make all my changes in code and manually add any new element. Furthermore, it seems very error prone as leaving out a (hidden) element by mistake will cause problems with form submissions.

💬 Support request
Status

Active

Version

6.2

Component

User interface

Created by

🇳🇱Netherlands tinto Amsterdam

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024