Create a custom date form element for date only widget

Created on 30 May 2025, 8 days ago

Problem/Motivation

Core's 'datetime' form element creates non-semantic h4 as the field label with the assumption that multiple child elements are involved which is not always the case. When the date type is 'Date only', there is only going to be a single input field so the normal label should be used in this case.

Steps to reproduce

Create a custom field with subfield 'date' and date type 'Date only'. When the widget is datetime_default, you will see some weird html that makes our flex layout look off cause of the different html styling. Core's widget does the same and returns alot of unnecessary markup.

<div data-drupal-selector="edit-field-some-date-0-value" class="form-item form-datetime-wrapper">
      <h4 class="form-item__label">Some Date</h4>
      <div id="edit-field-some-date-0-value" class="form-items-inline">
  <div class="js-form-item form-item js-form-type-date form-type--date js-form-item-field-some-date-0-value-date form-item--field-some-date-0-value-date form-item--no-label">
            <label for="edit-field-some-date-0-value-date" class="form-item__label visually-hidden">Date</label>
              <input data-drupal-selector="edit-field-some-date-0-value-date" type="date" id="edit-field-some-date-0-value-date" name="field_some_date[0][value][date]" value="" size="12" class="form-date form-element form-element--type-date form-element--api-date">
          </div>

</div>

</div>

Proposed resolution

Create a custom form element for the datetime_default widget when the date type is 'Date only'.

πŸ“Œ Task
Status

Active

Version

3.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States apmsooner

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024