craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.22k stars 626 forks source link

[5.x]: Required property not set on custom field object #15752

Open peteeveleigh opened 5 days ago

peteeveleigh commented 5 days ago

What happened?

Description

When looping through custom fields I was trying to automatically set the required attribute based on {{ customField.required }}. It looks like this property has been moved into {{ customField.layoutElement.required }} but the original property still exists and is not being set - it's always false.

Custom field properties. The required property is false, despite the field being set to 'required' Screenshot 2024-09-18 at 09 45 59

Same field, layoutElement Screenshot 2024-09-18 at 10 05 14

While I understand that this property has been moved into layoutElement, if the original property remains then should it also honour the required setting of the field for consistency's sake. At least until fully deprecated (if that's the plan) .

Steps to reproduce

  1. Create a custom field and set it to be required
  2. On the front-end loop through the custom fields and use the {{ customField.required }} property to set the required attribute on the field.

Expected behavior

The field should received a required attribute

Actual behavior

The {{ customField.required }} property is always false while the {{ customField.layoutElement.required }} property honours the setting in the CP.

Craft CMS version

5.4.4

PHP version

8.2.18

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

i-just commented 4 days ago

Hi, thanks for reporting. I raised a PR for this.