[BUG]: DATETIME empty field not saved correctly. #1245

Open
opened 2025-08-27 18:19:15 +00:00 by Tom van der Laan · 4 comments

What Happened?

If i create a non required datetime field using the OTHER (EMPTY) option for the db so the table matches how joomla saves datetime fields and there is no issue with newer mysql versions it does not save the field.

I get this error instead:

Save failed with the following error: Incorrect datetime value: '' for column db_extension.prefix_component_table.publish_up at row 1.

In order to fix this issue i had to add this to my save method in the admin view:

        if ($data['publish_up'] == '') {
            $data['publish_up'] = null;
        }

The next issue that arrose is that it did not save an empty value. because in the store function of the src/Table/View.php it is saving using $updateNulls = false;

I have no idea how to override this. But if i hard code it to true at the top it did save the null value like it was supposed to do.

Hope we can sort out what needs to be done to support datetime using the null option.

Steps to reproduce the Bug

add a datetime field with db default value NULL (OTHER -> EMPTY) to an admin view.
try to save the admin view with no date present.

expected: to save without date.
result: error could not save it.

Which Joomla version are you compiling in?

5.3

Which PHP version are you compiling in?

8.3

Which Joomla versions are you targeting?

5.3

Which PHP version are you targeting?

8.3

Which Web server is JCB running on?

litespeed

Which Relational Database is JCB running on?

mariadb 10.11

Which OS is JCB running on?

almalinux 9

Which JCB version are you using?

5.1.1 stable

Where in JCB did this issue occur?

Admin View(admin_view)

On which browsers did you encounter the issue?

Firefox, Safari

Additional Comments

No response

### What Happened? If i create a non required datetime field using the OTHER (EMPTY) option for the db so the table matches how joomla saves datetime fields and there is no issue with newer mysql versions it does not save the field. I get this error instead: Save failed with the following error: Incorrect datetime value: '' for column `db_extension`.`prefix_component_table`.`publish_up` at row 1. In order to fix this issue i had to add this to my save method in the admin view: ``` if ($data['publish_up'] == '') { $data['publish_up'] = null; } ``` The next issue that arrose is that it did not save an empty value. because in the store function of the src/Table/View.php it is saving using $updateNulls = false; I have no idea how to override this. But if i hard code it to true at the top it did save the null value like it was supposed to do. Hope we can sort out what needs to be done to support datetime using the null option. ### Steps to reproduce the Bug add a datetime field with db default value NULL (OTHER -> EMPTY) to an admin view. try to save the admin view with no date present. expected: to save without date. result: error could not save it. ### Which Joomla version are you compiling in? 5.3 ### Which PHP version are you compiling in? 8.3 ### Which Joomla versions are you targeting? 5.3 ### Which PHP version are you targeting? 8.3 ### Which Web server is JCB running on? litespeed ### Which Relational Database is JCB running on? mariadb 10.11 ### Which OS is JCB running on? almalinux 9 ### Which JCB version are you using? 5.1.1 stable ### Where in JCB did this issue occur? Admin View(admin_view) ### On which browsers did you encounter the issue? Firefox, Safari ### Additional Comments _No response_
Tom van der Laan added the
Bug
label 2025-08-27 18:19:15 +00:00
Owner

T o get a field to save as null you must set the default to EMPTY like this:

image.png

This will cause the field to behave as expected. We took this direction since leaving a default empty is an empty string.... be for it to be really empty, we opt for the EMPTY key word.... might need improvement, but it does the job.

T o get a field to save as null you must set the default to `EMPTY` like this: ![image.png](https://git.vdm.dev/attachments/43e9dec8-e46a-4e2b-9fcb-be658eaaa4c9) This will cause the field to behave as expected. We took this direction since leaving a default empty is an empty string.... be for it to be really empty, we opt for the `EMPTY` key word.... might need improvement, but it does the job.
Author
Member

Yes i know that is exactly what i did. But joomla still tries to put an empty string in it. wondering maybe because i left default empty in the field params. i'll go check that.

Yes i know that is exactly what i did. But joomla still tries to put an empty string in it. wondering maybe because i left default empty in the field params. i'll go check that.
Author
Member

Here are some screenshots of my field and my db settings of the field.

Here are some screenshots of my field and my db settings of the field.
Author
Member

Yes i know that is exactly what i did. But joomla still tries to put an empty string in it. wondering maybe because i left default empty in the field params. i'll go check that.

This was not the cause unfortunately.

> Yes i know that is exactly what i did. But joomla still tries to put an empty string in it. wondering maybe because i left default empty in the field params. i'll go check that. This was not the cause unfortunately.
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: joomla/Component-Builder#1245
No description provided.