paishin
paishin

Reputation: 258

How can I set a default date format for all backend fields in OctoberCms?

When I create a date field in OctoberCMS by default it is formatted as m/d/Y but I want to use d/m/Y instead.

Fortunately OctoberCMS allows date widgets to format the date before displaying using the 'format' attribute so this partially solves the problem.

This 'format' parameter is not available in all widgets, for example I want to create a 'list filter' which does not have it so I cannot change the date format. (https://octobercms.com/docs/backend/lists#filter-daterange)

Is there a way I can set the default format to be used by all elements?

enter image description here

Here is my config_list.yaml file:

title: Properties
modelClass: DP\Properties\Models\Property
list: $/dp/properties/models/property/columns.yaml
recordUrl: 'dp/properties/properties/update/:id'
noRecordsMessage: 'backend::lang.list.no_records'
recordsPerPage: 20
showSetup: true
showCheckboxes: true
defaultSort:
    column: updated_at
    direction: asc
toolbar:
    buttons: list_toolbar
    search:
        prompt: 'backend::lang.list.search_prompt'
filter: config_filter.yaml

And an here is a part of the config_filter.yaml file

...
    updated_at:
        label: 'Updated'
        type: daterange
        conditions: created_at >= ':after' AND created_at <= ':before'
        format: d-m-Y
...

And the controller

class Properties extends Controller
{
    public $implement = [
        'Backend\Behaviors\ListController',
        'Backend\Behaviors\FormController',
        'Backend\Behaviors\ReorderController'
    ];

    public $listConfig = 'config_list.yaml';
    public $formConfig = 'config_form.yaml';
    public $reorderConfig = 'config_reorder.yaml';

    public function __construct()
    {
        parent::__construct();
        BackendMenu::setContext('DP.Properties', 'main-menu-item');
    }

Upvotes: 0

Views: 1137

Answers (2)

paishin
paishin

Reputation: 258

You can change the default timezone used by all backend forms by editing 'backendTimezone' attribute in /config/cms.php' file and adding your timezone.

Upvotes: 0

MHewison
MHewison

Reputation: 866

In October the default date format is tied to the locale of the system. (within the backend).

To change the default date format, click on your user avatar in the top right and click "Back-end preferences". The default locale will be set at English (United States). You can change this to whatever you want. English (United Kingdom) should resolve the date format default. But I believe that it is only the US who use the m/d/Y format

Upvotes: 1

Related Questions