Page 1 of 1
Posted:
Wed Jul 19, 2006 6:25 am
by Aoirthoir
If I use the widget:type of date (these are for birth dates) I get a drop down of the years 2001-2010. Is there a way to change this?
Posted:
Wed Jul 19, 2006 9:18 am
by shannah
This is one of those simple things that I have been planning to deal with for a while but haven't got around to it. You need to make a modification to Dataface_QuickForm.php to make this work:
In the method _buildWidget(), there is a switch clause where it goes:
switch ( $widget['type'] ){
...
case 'htmlarea': ...
case 'calendar:'...
...
}
You need to add a special case for date as follows:
case 'date':
$el =& $form->addElement('date', $field['name'], $widget['label'], $widget);
break;
Now you can specify options for the date widget in the fields.ini file as follows:
[mydate]
widget:type=date
widget:language=en ; specify the language format of the date
widget:format='dMY' ; Specify the date format
widget:minYear=1956 ; The minimum year to select
widget:maxYear=2000 ; The maximum year to select
I have added this modification to my local dev copy so it will be part of the next minor release.
Best regards
Steve
Posted:
Wed Jul 19, 2006 10:21 am
by Aoirthoir
Thanks. We are just in the developement stages so I will keep an eye on this for now and update it when I need to.
Posted:
Sun Dec 03, 2006 12:23 pm
by njw
Hi Steve
I have used the date formatting command above and it comes up fine when editing, but in list and view mode the date is displayed in YYYY-MM-DD format. Is there a way to make it more user friendly e.g DD-mmm-YY (2-Dec-06) or something similar?
Many thanks
Neil
Posted:
Mon Dec 04, 2006 1:12 pm
by shannah
Yes.. You can override the display for any field in the delegate class using methods of the form:
%fieldname%__display(&$record)
e.g.:
- Code: Select all
function startdate__display(&$record){
return date('F d, Y', strtotime($record->strval('startdate')));
}
This would format the startdate field like 'February 25, 2006'.
Hope this helps..
-Steve
Posted:
Tue Dec 05, 2006 3:42 am
by njw
Sorry Steve. Doesn't change the output display at either list or detail level. Could it be because my field is a date datatype?
Neil
Posted:
Tue Dec 05, 2006 11:28 am
by shannah
This should work. I tested it before posting it. Can you double check your code. (e.g. make sure there are two underscores, etc...).
This strategy will work for any field regardless of type.
-Steve
Posted:
Tue Dec 05, 2006 12:05 pm
by njw
I've done a cut and paste on your code and edited in my fieldname ItemDate. Still showing dates as 2006-12-05.
The code is here:
function ItemDate__display(&$record){
return date('F d, Y', strtotime($record->strval('ItemDate')));
}
Cheers
Neil
Posted:
Tue Dec 05, 2006 1:37 pm
by shannah
Things that it could possibly be (checklist):
1. Name of ItemDate field is case sensitive.
2. The ItemDate field is actually in a different table than the delegate class for which the ItemDate__display() method is defined.
3. ... can't think of anything else right now ...
Let me know if it is either of those.
-Steve
Posted:
Tue Dec 05, 2006 2:15 pm
by njw
ItemDate is definitely the field name as spelled; code for delegate class is in the same directory as the fields.ini for the Items table.
I can't think of anything else either!
Neil