strange behaviour with calendar widget (date formatting)
Archived from the Xataface Users forum.
razzetto — Tue Sep 04, 2012 6:40 am
Hi Steve, hi all.
I have some problems with time fields (and tried different solutions, perhaps messing everything).
To avoid showing 01-01-1970 when the field is NULL, i entered, in the application delegate class for the table :
- Code: Select all
function data_intervento__display(&$record){ if ($record->val('data_intervento') == NULL){ return ""; } else { return date('d-m-Y', strtotime($record->strval('data_intervento'))); } }
and everything (in list and details views) works well.
switching to the edit view i had some problems: the date was always on the format Y-m-d; so i changed the setting in fields.ini for the widget:
- Code: Select all
[data_intervento] widget:type=calendar widget:ifFormat = %d-%m-%Y
but now i get a messy situation:
- when i enter the day with the calendar the field space is formatted good. (it lacks the red square, though, and it’s a required field)
for example if i enter the date of today, the field gets filled with 04-09-2012
-when i click on save, the field shows 2012-09-04.
this would be acceptable (not a great issue, come on), but..
if i now click on the calendar widget, it shows the date 05-03-2010 as a preselected date. mmmhhh.
if i comment out the calendar widget in fields.ini this strange calendar behaviour disappears, but of course i would get, in the edit view, the format Y-m-d.
any suggestions, ideas on why this happens? i really can’t get a clear view of the situation
Thanks,
Paolo
razzetto — Tue Sep 04, 2012 6:52 am
ok. i found the solution here http://xataface.com/forum/viewtopic.php?f=5&t=4245&start=0
i just needed to add
- Code: Select all
function data_intervento__pullValue(&$record, $element){ return date('d-m-Y', strtotime($record->strval('data_intervento')));
just to be sure….
in this case, i wonder, do i need a push_value definition?
thanks,
Paolo
shannah — Sat Sep 08, 2012 10:32 am
Yes. I think you do need a pushValue definition also.