ECA "form field: set as required" does not work with a file upload field with cardinality > 1

Created on 15 April 2025, 6 days ago

Problem/Motivation

ECA "form field: set as required" does not work with a file upload field with cardinality > 1

Steps to reproduce

Install drupal-cms
https://new.drupal.org/docs/drupal-cms/get-started/install-drupal-cms/in...

Confirm that the form validation is broken for file upload fields with cardinality > 1

Add a new "File upload" field to the node type `page`, call it "file", so the machine name is `field_file`
Allowed number of values:
Limited, 2
Create a new ECA
"set field_file as required"
event: build form
action: "form field: set as required"
field name: field_file

go to:
node/add/page
enter a title, enter a description
save

expected:
a validation error on field_file
got:
no validation error, the form is saved
... this is not what we want ...

Confirm form validation is working when cardinality = 1

go back to:
admin/structure/types/manage/page/fields/node.page.field_file
set cardinality to:
Limited, 1
Save settings

now, go to:
node/add/page
enter a title, enter a description
save
... as expected, we get a validation error

Confirm form validation is working when cardinality = unlimited

go back to:
admin/structure/types/manage/page/fields/node.page.field_file
set cardinality to:
Unlimited
Save settings

now, go to:
node/add/page
enter a title, enter a description
save
... as expected, we get a validation error

Proposed resolution

I'm not sure if this is an ECA issue, or a core issue.

After some initial investigation, I think the problem is related to the Ajax request generated when the upload button is clicked. I think this is somehow overriding the '#required' flag, so that when the form submit button is clicked, the form does not throw a validation error.

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany michaellenahan

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024