Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x]: Error summary doesn't correctly link to compound fields #16244

Closed
ryansupercool opened this issue Nov 29, 2024 · 2 comments
Closed

[5.x]: Error summary doesn't correctly link to compound fields #16244

ryansupercool opened this issue Nov 29, 2024 · 2 comments
Assignees
Labels

Comments

@ryansupercool
Copy link

What happened?

Description

For compound fields such as the lat/long field in addresses, the error summary doesn't link to the field when those fields are required but left empty.

The fields are also missing the error styling and messaging.

We discovered this when adding our own compound fields using a fieldset. It would be nice if BaseNativeField could handle errors in this situation nicer overall i.e. error summary and individual error styling on fields. The .input.errors > .text selector that applies the border doesn't work if you have a set of fields wrapped in a container div.

Note: We are using BaseNative field with useFieldset, true.

protected function inputHtml(?ElementInterface $element = null, bool $static = false): ?string
{
       $output = [];
       $output[] = Html::beginTag('div', ['class' => 'flex']);
       $output[] = Cp::textFieldHtml([]);
       $output[] = Cp::selectFieldHtml([]);
       $output[] = Html::endTag('div');

       return  implode("\n", $output);
}

Steps to reproduce

  1. Add the lat/long fields to the address element and make required.
  2. From the user edit page add a new address, leave the lat/long fields empty and save.
  3. Click the error links in the summary.

Expected behavior

Focus is set to the field when clicking the link.

Actual behavior

Focus isn't set.

Craft CMS version

5.5.3

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@i-just
Copy link
Contributor

i-just commented Dec 2, 2024

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

The subfields in the src/fieldlayoutelements/addresses/LatLongField.php were missing the data-error-key attribute. After adding this attribute to the latitude and longitude field, the errors on the fields show as expected and the error summary links work as intended. If you add this attribute to your compound field’s subfields, the errors and the summary should work as expected.

@brandonkelly
Copy link
Member

Craft 5.5.4 is out with that fix. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants