This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Greetings all,
This is my first forum post and I'm looking forward to receiving your golden nuggets of valuable wisdom.
I'm trying to figure out a way to adjust the format of the datepicker elements globally throughout the backend, primarily from d/m/Y (UK style) to m/d/Y (US style), based on the locale settings, or alternatively a new 'preferred date format' property added to the backend user class.
I have extended the UserPreference model and controller to allow this to be saved, which is working fine. I have been looking into a few approaches, including the following:
- Intercept the parsing of the YAML file and dynamically set the date format based on the contents of the above.
- Override the DatePicker class somehow and add my logic in there.
Before I get stuck down a rabbit hole of trying to extend/override core October CMS functionality, can anybody point me in the right direction? Perhaps there is a much easier way to do this.
Thanks
Jon
Last updated
Hi Jon, you can definitely use the backend.form.extendFields
event to do this. Just make sure the controller/widget model are the ones you want before making the changes in the event handler.
ref. https://octobercms.com/docs/api/backend/form/extendfields
You can use the following code in the handler:
$datepicker = $widget->getField('datepickerFieldName');
$datepicker->config['format'] = $yourFormatFromUserPreference;
Last updated
Also note: the backend defined locale should define this automatically... if the Backend Locale is set to "french", the datepicker format should be d/m/Y automatically.
1-5 of 5