5

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?

enter image description here

COil
  • 7,201
  • 2
  • 50
  • 98
Anton Smatanik
  • 587
  • 1
  • 9
  • 25

3 Answers3

7
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.

Maulik Savaliya
  • 1,262
  • 7
  • 17
2

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.

Maya Shah
  • 950
  • 7
  • 17
2

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 :(

Anton Smatanik
  • 587
  • 1
  • 9
  • 25
  • 1
    I've looked at the source code: there is made a check if the field is a date and if the field is nullable. You can set `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). – baris1892 Dec 25 '17 at 22:33