Issue Bug Closed

#81548TCA empty input with renderType => inputDateTime with dbType => date gives error on save

Marieke de Bruin 06/12/17, 11:51 updated 06/13/17, 12:43

Description

When I save a not filled (empty) date, I get the following error in CMS 8.7

1: These fields of record 1 in table "tx_my_ext" have not been saved correctly: birthdate! The values might have changed due to type casting of the database.

I have an extension with the following TCA

      'birthdate' => [
            'exclude' => 1,
            'label' => $labelReferencePrefix . 'tx_my_ext.birthdate',
            'config' => [
                'renderType' => 'inputDateTime',
                'dbType' => 'date',
                'type' => 'input',
                'size' => 7,
                'eval' => 'date',
                'checkbox' => 0,
                'default' => '0000-00-00'
            ],
        ],

and the following sql declaration in the ext_tables.sql

birthdate date DEFAULT '0000-00-00',

When I change the table to varchar, the date is saved as 0 while empty

I think the problem is in the 'eval' => 'date' according to the documentation

The field will evaluate the input as a date, automatically converting the input to a UNIX-time in seconds.

But this is only a problem when the value is empty, when it’s filled there is no problem.
I can’t remove the eval because this is required when you set 'renderType' => 'inputDateTime'

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.