Empty paragraph fields

Created on 3 May 2024, about 2 months ago
Updated 17 May 2024, about 1 month ago

Problem/Motivation

The paragraphs module offers a functionality of creating an empty initial paragraph item in the field widget when creating new content. It's a UI feature to save users an extra click to add an item on each paragraphs field.

If the paragraph field itself is optional, but the paragraph has fields inside it that are required, they would trigger a validation error on the page. This is fine when the user is creating new content, as the expectation is that there would be several required fields on the form.

On the other hand, when cloning existing content, I would expect to be able to hit save immediately. However, this is not the case if the existing content has an empty paragraphs field. Instead, the above behaviour can kick in, and hitting save will also be attempting to create that paragraph and triggers all this validation.

Steps to reproduce

1. Create a content type CC
2. Create a paragraph type PP
3. Add a required text field Req-F on PP
4. Add an optional paragraphs field PF on CC, and let it use PP paragraphs
5. In CC's "Manage form display" settings, set PF's "Default paragraph Type" to PP
6. Create a node of type CC, and remove the paragraph added in PF
7. Now try to clone this node

Expected result:
On the clone form, you directly scroll to the save button and hit save to get a clone node.

Actual result:
An empty paragraph has been added for PF, and form validation will complain about the empty Req-F field.

Proposed resolution

After the clone form is built, we loop over all paragraph fields on the node, and if they're empty on the node, we remove the generated empty item added (if present).

Remaining tasks

Implement fix and test it

User interface changes

When cloning a node with an empty paragraph field, the widget will always be empty, even if a "Default paragraph type" is set in the widget settings.

API changes

N/A

Data model changes

N/A

📌 Task
Status

RTBC

Version

1.0

Component

User interface

Created by

🇬🇧United Kingdom khaled.zaidan

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

Comments & Activities

Production build 0.69.0 2024