? Error

User tests: Successful: Unsuccessful:

avatar Bakual
Bakual
16 Nov 2013

The calendar formfield has two issues:

  • The value is always shown in the format 2013-11-16 00:00:00 even if the format parameter would ask to only show the date. This is actually a bug in JHtml::calendar().
  • The formfield ignores readonly and disabled attributes.

The first issue can be tested by editing a form definition file like /administrator/components/com_content/models/forms/article.xml and change he format value for the created field (or any other calendar type). Note that the shown value doesn't respect the format, but if you select a date it will respect it. Apply change and it will also affect the value shown.

The second issue can be tested by looking at the modified field in the form. It should be readonly but the shows the calendar select button and allows to change the value of the field using this button. This PR will properly set the attributes in the formfield so JHtml::calendar() doesn't show the button anymore.

Tracker: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=32730

avatar Bakual Bakual - open - 16 Nov 2013
avatar Bakual
Bakual - comment - 17 Nov 2013

Added a commit: The value 0000-00-00 00:00:00 would result in 1970-01-01 after formatting. Now it doesn't show at all anymore. Similar to the tooltip which doesn't show as well in this case.

avatar Bakual
Bakual - comment - 28 Nov 2013

Fixed the date format for readonly fields and tried to make Travis happy.

avatar fastslack
fastslack - comment - 4 Dec 2013

Please merge this patch for calendar field format :-)

avatar Bakual
Bakual - comment - 4 Dec 2013

We need at least one more test logged in the tracker. Especially for the latest change with the readonly field. Can you do that?

avatar fastslack
fastslack - comment - 4 Dec 2013

test was not good, because we use %d-%m-%Y format and JDate use d-m-Y format

maybe using str_replace could help:

$format = str_replace("%", "", $format);
avatar Bakual
Bakual - comment - 5 Dec 2013

test was not good, because we use %d-%m-%Y format and JDate use d-m-Y format

Actually, we don't use the format parameter together with JDate. So this can't be an issue imho. Did you really test it? Because I can't reproduce the issue.

avatar fastslack
fastslack - comment - 5 Dec 2013

Sorry, the problem was not the format. But the saved date is not being shown.

$ patch -p1 < 2531.patch 
patching file libraries/joomla/form/fields/calendar.php
patching file libraries/cms/html/html.php
patching file libraries/cms/html/html.php
patching file libraries/cms/html/html.php
patching file tests/unit/suites/libraries/joomla/form/fields/JFormFieldCalendarTest.php
patching file libraries/cms/html/html.php

date-bug

It always save '0000-00-00 00:00:00' and not the selected date.

avatar Bakual
Bakual - comment - 5 Dec 2013

I can explain why '0000-00-00 00:00:00' doesn't show. It's an intentional sideeffect of this change, because of the way the date is formatted and the timezone is calculated in it would return a funny date instead. I've decided to leave the field empty in this case.

However if you enter a real date, it should work fine. I've tested it with several different formats using com_content and my own component and it worked fine.

The screenshot looks like it's used in a 3rd party extension. Could I test it with that one?

avatar fastslack
fastslack - comment - 5 Dec 2013

The problem is in the format parameter because im using:

<field name="birthdate"  type="calendar" label="LABEL" description="DESC" size="10" class="inputbox" default="" format="%d-%m-%Y"/>

When i remove the format parameter, it can save but still not showing the saved date

Leave me an email and i ll show you the test site

avatar infograf768
infograf768 - comment - 7 Dec 2013

See the solution I propose in tracker for the Jalali date.

avatar Bakual
Bakual - comment - 7 Dec 2013

@infograf768 I'll have a look at it and also commented on tracker

@fastslack did you get my email? I have used the email address on your GitHub profile.

avatar Bakual
Bakual - comment - 9 Dec 2013

Latest commit will fix the non-gregorian calendars for the readonly/disabled fields by making the whole thing a bit simpler.
What I did is

  • Always load the JavaScript calendar, even if the field is readonly/disabled. Loading that will ensure that the overrides for the non-gregorian calendars still work.
  • Hide the button to open the calendar box when readonly or disabled using an inline-style display:none;
  • Remove the workaround code with the hidden inputbox since we no longer need it.
avatar mhehm mhehm - reference | - 24 Dec 13
avatar fastslack
fastslack - comment - 4 Feb 2014

I still having issues with calendar, when i save it in mysql format (1970-01-01). This is my form field:

<field  name="birthdate"    type="calendar" label="COM_BLABLA_BIRTHDATE_LABEL" description="COM_BLABLA_BIRTHDATE_DESC" size="10"    class="inputbox" />

And it shows empty value.

Why is the reason of the line 978 of libraries/cms/html/html.php
-> // Format value when not '0000-00-00 00:00:00', otherwise blank it as it would result in 1970-01-01. ?

That code is changing the value for nothing.

Also the format is bad, the default format use %, ex %Y-%m-%d and the JDate object format method use Y-m-d format.

avatar Bakual
Bakual - comment - 4 Feb 2014

I still can't reproduce the issue you see. Can you contact me on bakual@bakual.ch? Maybe we can figure out what is different in your case that causes the issue.

Why is the reason of the line 978 of libraries/cms/html/html.php
-> // Format value when not '0000-00-00 00:00:00', otherwise blank it as it would result in 1970-01-01. ?

If you pass 0000-00-00 00:00:00 through strftime() you'll get 1970-01-01 out, since that is the 0-value in Linux. Also it is more consistent with how the field initially shows (before you save it).

Also the format is bad, the default format use %, ex %Y-%m-%d and the JDate object format method use Y-m-d format.

The calendar uses the %Y-%m-%d format due to backward compatibility and because it is used by the JavaScript. Unfortunately we can't change that one easy at this time.

avatar fastslack
fastslack - comment - 4 Feb 2014

This pull request #3050 fix the problem partially

avatar Bakual Bakual - change - 13 Feb 2014
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-02-13 08:39:24
Labels
avatar Bakual Bakual - close - 13 Feb 2014
avatar Bakual Bakual - close - 13 Feb 2014
avatar Hackwar Hackwar - reference | 134ed5a - 13 Feb 14
avatar Bakual Bakual - head_ref_deleted - 12 May 2014
avatar Bakual Bakual - reference | 203f1df - 12 May 14

Add a Comment

Login with GitHub to post a comment