Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Localising Date Picker Fields in UserDefinedForm


Go to End


5 Posts   2476 Views

Avatar
willmorgan

Community Member, 11 Posts

3 August 2010 at 3:39am

Edited: 03/08/2010 4:50am

Hi,

I'm having trouble setting the date format to en_GB (dd-mm-yyyy) format when using a UserDefinedForm page.

In mysite/_config.php, I set the i18n config to my locale which seems to work elsewhere on the site, just not here. The DatePicker field inserts an en_US formatted date, and when submitted, the CMS validates it against en_GB so I'm pretty sure it's just down to the DatePicker.

I'm using 2.4.1

Any ideas?

Avatar
Willr

Forum Moderator, 5523 Posts

3 August 2010 at 6:39pm

The locale is hard coded in the UDF file. The files which you will need to edit are the EditableDateField.php file. getFormField() returns the datepicker so that needs to be passed the correct format using dateFormat (http://jqueryui.com/demos/datepicker/).

I have created a ticket for this work - http://open.silverstripe.org/ticket/5902.

Avatar
willmorgan

Community Member, 11 Posts

3 August 2010 at 9:02pm

Edited: 03/08/2010 9:22pm

Cheers Will..

I've updated EditableDateField.php to specify jQuery UI's dateFormat when datepicker is called on the element. For now I'm using i18n::get_date_format().

Use the file below if you like, hope it helps others.

Avatar
Willr

Forum Moderator, 5523 Posts

3 August 2010 at 9:12pm

Sweet does that work? If it does attach that file up on the ticket and I can integrate it. I think that would be useful. I thought about having the format in the CMS but that seems a very edge case.

Avatar
willmorgan

Community Member, 11 Posts

3 August 2010 at 9:28pm

Edited: 03/08/2010 9:28pm

Yep it works. I've upped the file on trac.

In the meantime I'm just overriding it with a custom form field in mysite/code/fields/