joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

CalendarField add time in filter also if showtime=false

Open prinswebdevelopment opened this issue 3 years ago • 3 comments

Steps to reproduce the issue

Joomla! 4 only Build a form with this field:

save the form, In FormController::save:623 ($validData = $model->validate($form, $data);) the value 2022-10-17 change in 2022-10-17 10:06:12 (with the current time)

This arises in the class/method CalendarField::filter:352 ($value = DateTime::createFromFormat($this->filterFormat, $value)->format('Y-m-d H:i:s');)

I run into the problem where I have a form confirmed (by user) before I save it. When I save the form with the data in the session I get an error (Call to a member function format() on bool ) on the same method (CalendarField::filter:352) because the filterFormat doesn't know that format is changed.

Expected result

The time should not be added to the value.

Actual result

Time is added to the value.

System information (as much as possible)

PHP 8.1.2 Joomla! 4.2.3

Additional comments

prinswebdevelopment avatar Oct 17 '22 08:10 prinswebdevelopment

This problem is also present in 5.1! I created a subform and included in it two instances of a date field. The first time it saved with no problem. On the second save I got the fatal error: Call to a member function format() on false / JROOT/libraries/src/Form/Field/CalendarField.php:400. It seems the filte is Y-m-d but the value has time too.

This is a serious bug!


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

ceford avatar May 03 '24 09:05 ceford

The first time it saved with no problem. On the second save I got the fatal error

That is diferent bug, the fix already there https://github.com/joomla/joomla-cms/pull/43234

Fedik avatar May 03 '24 11:05 Fedik

Thanks for that. I applied the patch and confirm I no longer get the fatal error.

ceford avatar May 03 '24 15:05 ceford

I confirm the bug. I have the same problem. When I used format="%Y-%m-%d" I receive a date filtered correctly. But with php 8.2 I have a message "Deprecated: Function strftime() is deprecated ". I have see in this post https://github.com/joomla/joomla-cms/issues/42790 to use filterFormat="Y-m-d" but that doesn't work :-(

Indeed with the code showed in this post that doesn't work : CalendarField::filter:352 ($value = DateTime::createFromFormat($this->filterFormat, $value)->format('Y-m-d H:i:s');)

Why you don't correct the code or replace the strftime() function ??? This issue is opened on Oct 17, 2022 :-( it's sad

fuscage avatar Aug 09 '24 21:08 fuscage

Please test PR #44114

Quy avatar Sep 19 '24 02:09 Quy