How can I change the default format used by the datetime picker of easyadminbundle?
I understand I must change something in config.yml
in type_options of field property. Or setup some different datetime format. But how or where?
easy_admin:
design:
assets:
js: ['assets/js/jquery.datetimepicker.full.js(Your Date picker Js)', 'assets/js/initDatePicker.js (Your code to initialize date picker on base of class "datepicker")']
css: ['assets/css/jquery.datetimepicker.css(Path of your datepicker css)']
form:
title: 'Your Title'
fields:
- { property: 'displayFrom', label: 'Display From', type_options: {'widget': 'single_text', 'format': 'dd/MM/yyyy H:mm', 'attr': {'class': 'datepicker'}} }
Just replace path of javascript and css and init datepicker, Also replace the field (displayFrom) with your form field.
In yml you can use datepicker class like this.
form:
title: 'Create User'
fields:
- { other fileds ...}
- { property: 'expiredAt', label: 'Credentials expired at', type_options: {'widget': 'single_text', 'format': 'dd/MM/yyyy H:mm', 'attr': {'class': 'datepicker'}} }
replace expiredAt with your field name. Hope this may helpful to you or anyone else.
So I figured it out, here is my solution:
Install:
https://github.com/stephanecollot/DatetimepickerBundle
config.yml:
- { property: 'credentialsExpireAt', type_options: {'widget': 'single_text', 'format': 'yyyy-MM-dd HH:mm', 'attr': {'class': 'datepicker' }} }
assets:
css:
- 'bundles/scdatetimepicker/css/datetimepicker.css'
js:
- 'bundles/scdatetimepicker/js/bootstrap-datetimepicker.min.js'
- 'bundles/easyadmin/javascript/init.js'
init.js:
$(function () {
$('.datepicker').datetimepicker({
minuteStep: 15
});
});
Problem is, that: "Leave empty" functionality for setting field on NULL, is now gone :(
nullable: false
to remove the "Leave empty" button: - { property: 'credentialsExpireAt', nullable: false, type_options: {'widget': 'single_text', 'format': 'yyyy-MM-dd HH:mm', 'attr': {'class': 'datepicker' }} }
. But now you may have to implement this functionality by yourself if you need this (but clearing e.g. the input field for an empty date (null) is okay I think).
Commented
Dec 25, 2017 at 22:33