Problem/Motivation

Required field indicator (*) appears twice

screenshot showing duplicate required indicator

Steps to reproduce

  1. Add a media image field or Address field to the article content type
  2. Add a checkbox to the article content type
  3. Create a conditional field to see that image/address is required if the checkbox is checked.

In HTML these field label will be look like

<legend>
  <span class="fieldset-legend">Image</span>
</legend>

when we applied a conditional field "required" for image/address fields then Required field indicator (*) appears twice.

In html it looks like

<legend class="form-required">
  <span class="fieldset-legend js-form-required form-required">Image</span>
</legend>
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kavya n n created an issue. See original summary.

kavya n n’s picture

Issue summary: View changes
kavya n n’s picture

Issue summary: View changes
kavya n n’s picture

Issue summary: View changes
kavya n n’s picture

Issue summary: View changes
kavya n n’s picture

Issue summary: View changes
liquidcms’s picture

I see the same on a checkbox widget for a List field.

- also fails validation even when something selected

malcomio made their first commit to this issue’s fork.

malcomio’s picture

I wasn't able to reproduce the issue mentioned in #4, but I think the problem is that the JS adds the "form-required" class to the legend and the span inside it.

This change fixes it for me in a subtheme of adminimal_theme

Probably need to check what happens in different themes - are there some themes where the class should go on the legend?

The default behaviour for a required field seems to be that it's on the span: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/themes/claro/...

Also the logic inside that JS file isn't very clear - would be good to review in more detail.

It was added in this commit for #3165898: If target field is multiple checkbox and condition is required then all checkboxes are being required.

benstallings’s picture

Status: Needs review » Needs work

merge conflicts with 4.x.

jcandan made their first commit to this issue’s fork.

jcandan’s picture

Version: 4.0.0-alpha5 » 4.x-dev
Assigned: kavya n n » Unassigned
Issue summary: View changes
Status: Needs work » Needs review

Rebased; fixed merge conflict. Also removed the legends.removeClass('form-required'); call.

jcandan’s picture

jcandan’s picture

Title: Required field indicator appears twice » Fix required field indicator appears twice
benstallings’s picture

Status: Needs review » Reviewed & tested by the community

Claude Code says:

Looks good. The fix is minimal, symmetric (handles both the add and remove paths), and targets the right layer of the DOM. The legendsspan line already applies both js-form-required and form-required, so removing the redundant legends line doesn't lose any functionality.

No concerns — this is a clean, safe two-line deletion. Ready to merge.

joelpittet’s picture

Status: Reviewed & tested by the community » Fixed

Thanks yes the CSS applies to that class regardless of what it's on so makes sense why it would double up in this case. Thanks for working on this everybody.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • jcandan committed 5a0fef0f on 4.x
    fix: #3476905 Required field indicator appears twice
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.