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
The date should get saved
Error : Save failed with the following error: Incorrect date value: '' for column j4
.a21bn_comdate_details
.nextdate
at row 1
Joomla 4
Labels |
Added:
No Code Attached Yet
|
1 thing is to allow NULL, another thing is to set a default value which is not in the constraints of the field type
Sorry, not able to understand can you explain it more
I think allowing null is not possible since it is getting validated in core Joomla, right?
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
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-08-29 18:25:21 |
Closed_By | ⇒ | brianteeman |
@madanedeepali Just look at the checked_out_time column in your SQL and you can see how it is done.
@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 Just look at the checked_out_time column in your SQL and you can see how it is done.
@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.
@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
@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:
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 store
method of that table class should have "true" as default value for the "$updateNulls" parameter, see again example from the ContactTable class:
public function store($updateNulls = true)
...
Does this help?
@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 totrue
. See here the ContactTable class as an example: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
store
method of that table class should have "true" as default value for the "$updateNulls" parameter, see again example from the ContactTable class:public function store($updateNulls = true) ...
Does this help?
Done the changes in the table as mentioned above still not working
@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; } }
@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.
""
is not a valid DATE for DEFAULT