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

3 Answers 3

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.

5
  • 1
    Problem is, that: "Leave empty" functionality for setting field on NULL, is now gone :( Commented Mar 27, 2017 at 14:35
  • Means you do not want to mark that field as required, am i right? Form should be submitted if user will not select the date. am i right? Commented Mar 28, 2017 at 4:23
  • Yes, problem is, that now when I click on Leave empty checkbox, field won't hide and value is not setup on null. Image: imgur.com/a/hNpVU Commented Mar 28, 2017 at 7:31
  • If you check the check box then what will be the database value after submit the form for these 2 fields which you have in image. Commented Mar 28, 2017 at 8:34
  • Yes, and normally would this field after hitting the button hide and value would be deleted. Commented Mar 28, 2017 at 8:56
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.

1
  • Problem is, that: "Leave empty" functionality for setting field on NULL, is now gone :( Commented Mar 27, 2017 at 13:41
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 :(

1
  • 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
    Commented Dec 25, 2017 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.