Problem/Motivation
On a large webform the Build page (/admin/structure/webform/manage/{webform}) gets very slow to load and to work with. Every save goes back to that page, so editors pay the cost again after each change.
WebformUiEntityElementsForm::getElementRow() gives every row a "Parent element" select (parent_key) whose options are every container on the form (::getParentOptions()). The select is hidden unless "Show row weights" is on; with drag handles, tabledrag only copies a key into it. So the page size grows with rows × containers.
On a real form with 613 elements and 297 containers (wizard pages plus container-like elements):
- 613 selects × 298 options = 183,000
<option>tags; - 18 MB of the page's 25 MB of HTML (3.7 MB compressed);
- 183,000 of the page's 207,000 DOM nodes.
The select was added for accessibility in #2985557: [accessibility] Setting parent key via 'Show weights' is disabled when building a webform., so that the parent can be set without drag-and-drop. That needs to keep working.
Steps to reproduce
- Create a webform with many wizard pages, each holding a few elements (for example 100 pages and 500 elements).
- Open its Build page and look at the page size and the number of
<option>elements inselect.row-parent-key.
Proposed resolution
Render parent_key as a text field instead of a select, and add one <datalist> of the container keys to the form, referenced by every row's field (list="webform-ui-parent-options"). Each option keeps the container's title as its label.
- Drag-and-drop is unchanged: tabledrag's
matchaction setstargetElement.valueon a text field just as it does on a select. - With "Show row weights" the field is visible, labelled as before ("Parent element @title", visually hidden), and the browser suggests the container keys and titles as you type. It stays usable from the keyboard, which is what #2985557: [accessibility] Setting parent key via 'Show weights' is disabled when building a webform. asked for.
::validateForm()already reports a parent that does not exist ("Parent %parent_key does not exist.") and parent loops, so a typed value is checked.
On the 613-element form this brings the page from 25 MB to 5 MB of HTML (0.2 MB compressed), from 207,000 to 24,700 DOM nodes, render time from 0.74 s to 0.41 s and peak memory from 189 MB to 80 MB.
The change touches WebformUiEntityElementsForm (::buildForm() adds the datalist, ::getElementRow() renders the text field) and extends WebformUiElementTest:
- no
select.row-parent-key; the text field points at the datalist, which lists the containers; - moving an element to another container by typing its key saves;
- an unknown parent shows "Parent missing does not exist.".
A merge request from the issue fork will follow.
Remaining tasks
- Merge request.
- Review, especially the "Show row weights" experience.
- Consider whether a site may rely on
parent_keybeing a select in a form alter.
User interface changes
With "Show row weights", the Parent column is a text field with suggestions instead of a dropdown. Nothing changes with drag handles.
API changes
None. The form element webform_ui_elements[KEY][parent_key] keeps its name and value; its #type changes from select to textfield, and the form gets a webform_ui_parent_options datalist.
Data model changes
None.
Issue fork webform-3642281
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
olena.karlova commentedComment #4
olena.karlova commentedMerge request !983 is ready for review: the parent field is a text field with one shared datalist, and
WebformUiElementTestcovers it.