#states: alternative fix for datetime element

Created on 15 July 2025, about 11 hours ago

Problem/Motivation

πŸ› [PP-1] #states attribute does not work on #type datetime Postponed has >10 years of comments, multiple postponed solutions, and an MR that is now stale.
This issue proposes an *alternate implementation* that avoids the blockers
identified there.

#states do not work with 'datetime' form elements:

  • Toggling visibility of the form element fails since there's no wrapper container to target.
  • Trying to toggle disabled fails since we can't find the nested form elements to disable.
  • Trying to toggle "required" fails since we can't find the label to add the right class(es) to.
  • ...

Proposed resolution

  • Fix datetime element the way details elements do

Remaining tasks

TBD

User interface changes

#states actually works on datetime form elements.

Original Report

While trying to create a custom field widget containing a "datetime" form element, I discovered that the #states attribute does not work on it.

Some states can be achieved with a workaround: put the datetime element in a container, and put the #states on the container. But this is obviously no clean fix, and it doesn't work for all states. (Works for "visible" for example, but not for "required".)

I was not able to figure out why this is not working, but I noticed that there have been a lot of issues regarding the #states attribute in the issue tracker. Most of them for were for specific elements like submit buttons, select elements with multiple values, ...

πŸ› Bug report
Status

Needs review

Version

11.0 πŸ”₯

Component

theme system

Created by

πŸ‡¨πŸ‡¦Canada joelpittet Vancouver

Live updates comments and jobs are added and updated live.
  • Contributed project blocker

    It denotes an issue that prevents porting of a contributed project to the stable version of Drupal due to missing APIs, regressions, and so on.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024