Problem/Motivation

The InputDemo form contains default values for 2 date related elements:


    // Date.
    $form['expiration'] = [
      '#type' => 'date',
      '#title' => $this->t('Content expiration'),
      '#default_value' => ['year' => 2020, 'month' => 2, 'day' => 15],
      '#description' => 'Date, #type = date',
    ];

    // Date-time.
    $form['datetime'] = [
      '#type' => 'datetime',
      '#title' => 'Date Time',
      '#date_increment' => 1,
      '#date_timezone' => date_default_timezone_get(),
      '#default_value' => date_default_timezone_get(),
      '#description' => $this->t('Date time, #type = datetime'),
    ];

However, these are not displayed.

Steps to reproduce

1. Enable Form Examples
2. View /examples/form-api-example/input-demo
3. Confirm default value for "Content expiration"
4. Confirm default value for "Date Time"

CommentFileSizeAuthor
form_api-timedefaults.png12.1 KBtyler36

Issue fork examples-3391497

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

tyler36 created an issue. See original summary.

tyler36’s picture

Status: Active » Needs review
schillerm’s picture

Hi tyler, I tested out MR !28 and it fixes the problem. Default dates now showing.
Tested on D9.5.0 site (php 8.1).
+1 for RTBC from me.

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

avpaderno’s picture

I have updated the issue fork which was one commit behind the upstream repository.

avpaderno’s picture

Title: Time-related field not showing default values » Time-related fields do not show their default values

  • apaderno committed e84eae82 on 4.0.x authored by tyler36
    Issue #3391497: Time-related fields do not show their default values
    
avpaderno’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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