21299 Posts in 5735 Topics by 2603 members
| Go to End | Next > | |
| Author | Topic: | 1399 Views |
-
DateTime/datepicker format problems

16 March 2012 at 11:24pm
Hi all,
This is driving me mad! I've searched the forums, the api, the internet for any clues that might help me with this problem and I haven't found anything that works. I'm trying to extend the Page class and add two fields - a start date and end date = for an events page on my site.
The fields appear fine, but whenever I choose a date with the datepicker, it fills the new field out in the wrong format - it uses MM/dd/YYYY when it should be returning dd/MM/YYYY.
Can anyone tell me what I'm doing wrong here?
I'm using the 3.0.0 beta, which I appreciate isn't a finished product, as I'm hoping to learn SilverStripe before v3 is officially released.
Thanks,
Loz
class EventPage extends Page {
static $db = array (
'EventStartDate' => 'Date',
'EventFinishDate' => 'Date'
);
static $has_one = array (
);
function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', $startDateField = new DateField('EventStartDate','Event Start Date'), 'Content');
$startDateField->setConfig('showcalendar', true);
$startDateField->setConfig('dateformat', 'dd/MM/YYYY');
$fields->addFieldToTab('Root.Main', $endDateField = new DateField('EventFinishDate','Event Finish Date'), 'Content');
$endDateField->setConfig('showcalendar', true);
$endDateField->setConfig('dateformat', 'dd/MM/YYYY');
return $fields;
}}
-
Re: DateTime/datepicker format problems

16 March 2012 at 11:26pm
Hi,
if it helps this is how I do it...
$df->setConfig('showcalendar', true);
$df->setLocale('en_GB');
$df->setConfig('dateformat', 'dd/MM/YYYY'); -
Re: DateTime/datepicker format problems

16 March 2012 at 11:36pm
Hi swaiba,
I tried using setLocale() like you suggested but it made no difference.
Thanks for the quick reply,
Loz
-
Re: DateTime/datepicker format problems

16 March 2012 at 11:43pm
is you site setup with the right locale also? (you would have had defaulted to en_US on the ss install)
I *know* that code works on my systems...
-
Re: DateTime/datepicker format problems

16 March 2012 at 11:47pm
I'm sure I set the site up with UK locale, the following line is in mysite/_config.php:
i18n::set_locale('en_GB');
Unless I missed something and you can set it somewhere else?
Thanks
-
Re: DateTime/datepicker format problems

17 March 2012 at 12:10am
actually i think i see it...
$fields->addFieldToTab('Root.Main', $startDateField = new DateField('EventStartDate','Event Start Date'), 'Content');
$startDateField->setConfig('showcalendar', true);
$startDateField->setConfig('dateformat', 'dd/MM/YYYY');try this instead...
$startDateField = new DateField('EventStartDate','Event Start Date')
$startDateField->setConfig('showcalendar', true);
$startDateField->setConfig('dateformat', 'dd/MM/YYYY');
$fields->addFieldToTab('Root.Main', $startDateField, 'Content'); -
Re: DateTime/datepicker format problems

17 March 2012 at 12:22am
No joy
Just to confirm; the field will accept the date if I input it manually in the correct format. It's just that the datepicker fills the form with the wrong format when choosing a date.
I wondered if it might have something to do with the DateField_View_JQuery class as detailed here: http://api.silverstripe.org/trunk/sapphire/forms/DateField_View_JQuery.html?
Cheers,
Loz
| 1399 Views | ||
| Go to Top | Next > |


