Years in Widget:type Date

A place for users and developers of the Xataface to discuss and receive support.

Postby Aoirthoir » Wed Jul 19, 2006 6:25 am

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?
Aoirthoir
 
Posts: 420
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Wed Jul 19, 2006 9:18 am

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
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Aoirthoir » Wed Jul 19, 2006 10:21 am

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.
Aoirthoir
 
Posts: 420
Joined: Wed Dec 31, 1969 5:00 pm

Postby njw » Sun Dec 03, 2006 12:23 pm

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
njw
 
Posts: 280
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Mon Dec 04, 2006 1:12 pm

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
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby njw » Tue Dec 05, 2006 3:42 am

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
njw
 
Posts: 280
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Tue Dec 05, 2006 11:28 am

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
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby njw » Tue Dec 05, 2006 12:05 pm

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
njw
 
Posts: 280
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Tue Dec 05, 2006 1:37 pm

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
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby njw » Tue Dec 05, 2006 2:15 pm

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
njw
 
Posts: 280
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 38 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved