No Code Attached Yet
avatar madanedeepali
madanedeepali
29 Aug 2023

Steps to reproduce the issue

Create a date field in the XML form

field name="nextdate" type="calendar" class="inputbox" filter="safehtml" label="COM_COMDATE_FORM_LBL_COMDATEDETAIL_NEXTDATE" description="COM_COMDATE_FORM_DESC_COMDATEDETAIL_NEXTDATE" hint="COM_COMDATE_FORM_LBL_COMDATEDETAIL_NEXTDATE"
and in the SQL create a table with the default value null as follows

CREATE TABLE IF NOT EXISTS #__comdate_details(id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,

state TINYINT(1) NULL DEFAULT 1,
ordering INT(11) NULL DEFAULT 0,
checked_out INT(11) UNSIGNED,
checked_out_time DATETIME NULL DEFAULT NULL ,
created_by INT(11) NULL DEFAULT 0,
modified_by INT(11) NULL DEFAULT 0,
name VARCHAR(255) NULL DEFAULT "",
nextdate DATE NULL DEFAULT NULL,
PRIMARY KEY (id)
) DEFAULT COLLATE=utf8mb4_unicode_ci;
`
facing error incorrect date field when trying to save the field without selecting a date in the date field Refer to the image
Screenshot 2023-08-29 at 10 12 40 PM

Expected result

The date should get saved

Actual result

Error : Save failed with the following error: Incorrect date value: '' for column j4.a21bn_comdate_details.nextdate at row 1

System information (as much as possible)

Joomla 4

Additional comments

avatar madanedeepali madanedeepali - open - 29 Aug 2023
avatar alikon
alikon - comment - 29 Aug 2023

"" is not a valid DATE for DEFAULT

avatar joomla-cms-bot joomla-cms-bot - change - 29 Aug 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 29 Aug 2023
avatar madanedeepali
madanedeepali - comment - 29 Aug 2023

@alikon So what can we consider or add the default date when we have set the default value as null for it in db

avatar alikon
alikon - comment - 29 Aug 2023

1 thing is to allow NULL, another thing is to set a default value which is not in the constraints of the field type

avatar madanedeepali
madanedeepali - comment - 29 Aug 2023

Sorry, not able to understand can you explain it more

avatar madanedeepali
madanedeepali - comment - 29 Aug 2023

I think allowing null is not possible since it is getting validated in core Joomla, right?

avatar brianteeman
brianteeman - comment - 29 Aug 2023

The sql for the database table you are creating is wrong.
This is not a bug in the core of joomla so I am closing this.

The forum is a better place for support https://forum.joomla.org

avatar brianteeman brianteeman - change - 29 Aug 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-08-29 18:25:21
Closed_By brianteeman
avatar brianteeman brianteeman - close - 29 Aug 2023
avatar richard67
richard67 - comment - 29 Aug 2023

@madanedeepali Just look at the checked_out_time column in your SQL and you can see how it is done.

avatar madanedeepali madanedeepali - change - 30 Aug 2023
The description was changed
avatar madanedeepali madanedeepali - edited - 30 Aug 2023
avatar madanedeepali
madanedeepali - comment - 30 Aug 2023

@richard67 changed the sql query to nextdate DATE NULL DEFAULT NULL,
but still not able to save the date field facing the same error, Can you please help me can I fix this issue where do I need to update the code

avatar brianteeman
brianteeman - comment - 30 Aug 2023

@madanedeepali Just look at the checked_out_time column in your SQL and you can see how it is done.

avatar richard67
richard67 - comment - 30 Aug 2023

@richard67 changed the sql query to nextdate DATE NULL DEFAULT NULL,
but still not able to save the date field facing the same error, Can you please help me can I fix this issue where do I need to update the code

@madanedeepali In Joomla we only use DATETIME columns, not DATE columns. Please try again with a DATETIME column.

avatar madanedeepali
madanedeepali - comment - 30 Aug 2023

@richard67 changed the sql query to nextdate DATE NULL DEFAULT NULL,
but still not able to save the date field facing the same error, Can you please help me can I fix this issue where do I need to update the code

@madanedeepali In Joomla we only use DATETIME columns, not DATE columns. Please try again with a DATETIME column.

No, still it does not work when used as DATETIME for the checked_out_time column it saves the current date and time

avatar richard67
richard67 - comment - 30 Aug 2023

@madanedeepali How does your form save data in database? Does it use a model, and does this use a table class? If so, this table class needs to support NULL values, i.e. the $_supportNullValue class variable has to be set to true. See here the ContactTable class as an example:

https://github.com/joomla/joomla-cms/blob/4.3-dev/administrator/components/com_contact/src/Table/ContactTable.php#L38-L44

class ContactTable extends Table implements VersionableTableInterface, TaggableTableInterface
{
    use TaggableTableTrait;

    /**
     * Indicates that columns fully support the NULL value in the database
     *
     * @var    boolean
     * @since  4.0.0
     */
    protected $_supportNullValue = true;
...

And the storemethod of that table class should have "true" as default value for the "$updateNulls" parameter, see again example from the ContactTable class:

https://github.com/joomla/joomla-cms/blob/4.3-dev/administrator/components/com_contact/src/Table/ContactTable.php#L79

public function store($updateNulls = true)
...

Does this help?

avatar madanedeepali
madanedeepali - comment - 30 Aug 2023

@madanedeepali How does your form save data in database? Does it use a model, and does this use a table class? If so, this table class needs to support NULL values, i.e. the $_supportNullValue class variable has to be set to true. See here the ContactTable class as an example:

https://github.com/joomla/joomla-cms/blob/4.3-dev/administrator/components/com_contact/src/Table/ContactTable.php#L38-L44

class ContactTable extends Table implements VersionableTableInterface, TaggableTableInterface
{
    use TaggableTableTrait;

    /**
     * Indicates that columns fully support the NULL value in the database
     *
     * @var    boolean
     * @since  4.0.0
     */
    protected $_supportNullValue = true;
...

And the storemethod of that table class should have "true" as default value for the "$updateNulls" parameter, see again example from the ContactTable class:

https://github.com/joomla/joomla-cms/blob/4.3-dev/administrator/components/com_contact/src/Table/ContactTable.php#L79

public function store($updateNulls = true)
...

Does this help?

Done the changes in the table as mentioned above still not working

avatar madanedeepali
madanedeepali - comment - 3 Sep 2023

@richard67 Thank you so much for the help...The above code snippet helped when added below code snippet in the table file store function since as you mentioned above In Joomla we only use DATETIME columns, not DATE columns.

public function store($updateNulls = true)

if(!($this->id)) { if (empty($this->nextdate)) { $this->nextdate = NULL; } }

avatar jbrailas
jbrailas - comment - 23 Apr 2024

@richard67 I think that this information (problem & answer) should be in the documentation in Potential_backward_compatibility_issues_in_Joomla_4 as it will help a lot of devs with old components.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41519.

Add a Comment

Login with GitHub to post a comment