Webform conditional logic breaks when a referenced element is deleted

Created on 8 May 2025, 2 months ago

Problem/Motivation

When a webform element is removed, any conditional logic (states, visibility, required conditions, etc.) that references this deleted element remains in the webform configuration. This leads to broken behavior such as required fields not being enforced or elements not being shown/hidden as expected. There is no warning or automatic cleanup of conditions referencing non-existent elements.

This can cause significant issues in production forms if element removal is not carefully audited.

Steps to reproduce

  1. Create a webform with the following elements:
    • Element A (e.g. a select or checkbox)
    • Element B (e.g. a textfield), which has a state condition based on Element A
  2. Save the webform.
  3. Edit the webform and delete Element A.
  4. Save the webform again.
  5. Observe that Element B's condition is now broken: it may no longer appear, or it might not be required even though it should be.

Proposed resolution

  • When an element is deleted from a webform, scan the form for any conditions or states referencing it, and either:
    • Automatically remove those conditions; or
    • Warn the user that other elements depend on the deleted one and require manual review.
  • Optionally add validation that blocks saving if a condition references a non-existent element.

Remaining tasks

  • Confirm behavior with multiple element types and nested structures.
  • Write patch or update relevant form builder logic.
  • Add test coverage for deleting elements with dependencies.
  • Update documentation, if needed.

User interface changes

  • Warning or confirmation message when deleting an element that is referenced by conditions.

API changes

  • None expected unless utility methods are added for dependency scanning.

Data model changes

  • None expected.
🐛 Bug report
Status

Active

Version

6.3

Component

Code

Created by

🇵🇱Poland jorgik

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

Comments & Activities

Production build 0.71.5 2024