datetime input inside table cannot be submitted

Created on 24 October 2025, 14 days ago
Updated 30 October 2025, 7 days ago

Problem/Motivation

When submitting a form with a datetime element embedded in a table, the validation returns following error, regardless of the value being input:

The date is invalid. Enter a date in the correct format.

Whether or not I add a default value (in the form of a DrupalDateTime object) does not change the outcome.

Steps to reproduce

Create following form, submit a date + time and submit.

<?php
    public function buildForm(array $form, FormStateInterface $form_state) {
        return [
            "table" => [
                "#type" => "table",
                0 => [
                    "datetime" => ['#type' => 'datetime'],
                ]
            ],
            'submit' => ['#type' => 'submit', '#value' => $this->t('Submit')],
        ];
    }

Own investigations

I compared the behavior of the form-elements date and datetime both embedded and not embedded in a table, using the below form. The only element that fails to validate is the datetime in the table.

<?php
    public function buildForm(array $form, FormStateInterface $form_state) {
        dpm($form_state, "in build");

        return [
            "date" => ['#type' => 'date'],
            "datetime" => ['#type' => 'datetime'],
            "table" => [
                "#type" => "table",
                0 => [
                    "date" => ['#type' => 'date'],
                    "datetime" => ['#type' => 'datetime'],
                ]
            ],
            'submit' => ['#type' => 'submit', '#value' => $this->t('Submit')],
        ];
    }

    public function validateForm(array &$form, FormStateInterface $form_state) {
        dpm($form_state, "in validate");
    }

Checking the state of the form_state array, I noticed some differences between both cases for the datetime element:

in build =>
Drupal\Core\Form\FormState {#2109 ▼
  // ...
  #input: array:7 [▼
    "date" => "2003-11-10"
    "datetime" => array:2 [▼
      "date" => "2003-11-10"
      "time" => "10:11:12"
    ]
    "table" => array:1 [▼
      0 => array:2 [▼
        "date" => "2003-11-10"
        "datetime" => array:2 [▼
          "date" => "2003-11-10"
          "time" => "10:11:12"
        ]
      ]
    ]
    "op" => "Submit"
    "form_build_id" => "form-vP_AbdW3L3eBPFLlVxCnxVUVIVAc4J8l8dN_S9iC5Hg"
    "form_token" => "GX3ea_aizYFOzexOyOoyekdXlx8QJnYOWd4_zKrYJ8g"
    "form_id" => "test_form"
  ]
}

in validate =>
Drupal\Core\Form\FormState {#2276 ▼
  // ...
  #values: array:8 [▼
    "date" => "2003-11-10"
    "datetime" => Drupal\Core\Datetime\DrupalDateTime {#1375 ▶}
    "table" => array:1 [▼
      0 => array:2 [▼
        "date" => "2003-11-10"
        "datetime" => array:2 [▼
          "date" => "2003-11-10"
          "time" => "10:11:12"
        ]
      ]
    ]
    "submit" => Drupal\Core\StringTranslation\TranslatableMarkup {#1507 ▶}
    "form_build_id" => "form-ufT2Mk6QpPV1cY8ZdFvhchQ9YrX08ibUYpwzGzMNU1s"
    "form_token" => "GX3ea_aizYFOzexOyOoyekdXlx8QJnYOWd4_zKrYJ8g"
    "form_id" => "test_form"
    "op" => Drupal\Core\StringTranslation\TranslatableMarkup {#1507 ▶}
  ]
  #input: array:7 [▼
    "date" => "2003-11-10"
    "datetime" => array:2 [▼
      "date" => "2003-11-10"
      "time" => "10:11:12"
    ]
    "table" => array:1 [▼
      0 => array:2 [▼
        "date" => "2003-11-10"
        "datetime" => array:2 [▼
          "date" => "2003-11-10"
          "time" => "10:11:12"
        ]
      ]
    ]
    "op" => "Submit"
    "form_build_id" => "form-vP_AbdW3L3eBPFLlVxCnxVUVIVAc4J8l8dN_S9iC5Hg"
    "form_token" => "GX3ea_aizYFOzexOyOoyekdXlx8QJnYOWd4_zKrYJ8g"
    "form_id" => "test_form"
  ]
}

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Here we see a difference between the values in the #values array:

  • Not in a table: DrupalDateTime object
  • In a table: array of date + time strings (same as in the #input array)
🐛 Bug report
Status

Active

Version

11.0 🔥

Component

forms system

Created by

Live updates comments and jobs are added and updated live.
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.

No activities found.

Production build 0.71.5 2024