Javascript error when field in closed details is required and form is submitted

Created on 18 July 2016, about 9 years ago
Updated 21 August 2025, 8 days ago

Problem/Motivation

It should be possible to set a field to required which is under a "details" element and have the javascript validation work correctly when the details element is not open.

For example, we want a menu link to be required when creating a node, so we set:

    $form['menu']['enabled']['#required'] = TRUE;
    $form['menu']['link']['title']['#required'] = TRUE;

In a hook_form_node_form_alter

This means that when submitting the form without checking the "Provide a menu link" checkbox, the user should be shown a validation error popup box. This works fine when the Menu Settings dropdown is expanded, but when it's closed a javascript error is produced:

"An invalid form control with name='menu[enabled]' is not focusable."
"An invalid form control with name='menu[title]' is not focusable."

Proposed resolution

Possibly - Check if the required field is hidden under a details element, and open the element before focussing the field?

Apologies if this is filed in the wrong place, I did some searching and couldn't find where the validation kicks in.

🐛 Bug report
Status

Closed: duplicate

Version

11.0 🔥

Component

forms system

Created by

🇦🇺Australia acbramley

Live updates comments and jobs are added and updated live.
  • Needs manual testing

    The change/bugfix cannot be fully demonstrated by automated testing, and thus requires manual testing in a variety of environments.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024