Field validation fails when a datetime object is used within a table.

// works
$form['foo'] = [
'#title' => $this->t('Foo'),
'#type' => 'datetime',
];
$form['sleep']['days'] = [
'#type' => 'table',
'#header' => ['#markup' => 'Header']
];
// fails
$form['sleep']['days']['bar'] = [
'#title' => $this->t('Bar'),
'#type' => 'datetime',
];
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 2703941-1.patch | 1.36 KB | priya.chat |
| #2 | datetime-table-2703941.patch | 734 bytes | dpi |
| datetimetable.jpg | 82.25 KB | dpi |
Comments
Comment #2
dpiNo idea if this is the right way to go.
Comment #3
dpiI notice there is no DrupalDateTime object in the values either...
Comment #7
alexdmccabeThe issue is in core/lib/Drupal/Core/Form/FormBuilder.php, around line 1298, at the end of FormBuilder::handleInputElement().
The issue is that the parent table element has already been run through the
FormBuilder::handleInputElementmethod and set a value, and soNestedArray::keyExistsreturnsTRUE. So in worrying that a#value_callbackmay have already set a value, we prevent values generated by a#value_callbackfrom setting properly.I tested this theory by removing the if statement and just letting
run. It worked fine.
Comment #17
dpiComment #18
priya.chat commentedHi , I have tried to put extra check and not to remove mentioned condition so that we can achieve the required result.
Comment #19
amietpatial commentedIt would be great if someone can add steps to reproduce, thanks.
Comment #20
smustgrave commentedSeems #18 had some failures.