I have two fields in my admin/componsents/com_xxxxx/models/forms/xxxxx.xml file.
these feed into an input form for administrators on the back end of Joomla 2.5
<field name="f_start" type="calendar" class="inputbox"
required="true"
format="%Y-%m-%d %H:%M:%S"
default="0000-00-00 09:30:00"
label="COM_xxxxx_F_START"
description="COM_xxxxx_F_START_DESC"
filter="safehtml" />
<field name="f_end" type="calendar" class="inputbox"
required="true"
format="%Y-%m-%d %H:%M:%S"
default="0000-00-00 19:30:30"
label="COM_xxxxx_F_END"
description="COM_xxxxx_F_END_DESC"
filter="safehtml" />
These are essentially start and end dates of when an article is published.
however when selecting the datepicker/calendar icon and choosing a date the
field is updated to the date chosen but keeps the 09:30:00 default start time.
this seems to work for times between 01:30:00 through to 11:30 any afternoon times get reset to now when a date is selected.
can anyone explain why?
or how to keep the default times on the date selector?
if the end date could also default to 28 days from the start date?
thanks in advance.
When clicking on the calendar icon, the calendar widget tries to position itself on the date contained in the corresponding text field. As
0000-00-00is an invalid date, theDate.parseDatefunction inmedia/system/js/calendar-uncompressed.jstries to guess the date from all components of the format string.0000-00-00 09:30:00is recognized as Sep 30, because09 < 12, so it looks like a month number, and thus it returnsSep 30, 9:30. On the other hand,0000-00-00 19:30:00is not recognized as any valid date, and the function returnstoday. Hence the difference in the time part.If you look at the XML form files for com_content for example, you’ll see that they don’t use default values for the calendar fields.
You could however create a custom field type derived from JFormFieldCalendar which would give you full flexibility. For example:
forms/whatever.xml
fields/pubdatecalendar.php
or whatever suits your particular application better.