Customize editable datapicker in List View

34 views
Skip to first unread message

Aleksandr O.

unread,
Jul 9, 2020, 8:31:54 AM7/9/20
to sonata-users
Hi all!

I am trying to customize an editable datepicker field in a view list sonata admin.

Configuration:

symfony  v4.4

$ composer show | grep sonata
sonata
-project/admin-bundle              3.65.0  The missing Symfony Admin Generator
sonata
-project/block-bundle              3.18.4  Symfony SonataBlockBundle
sonata
-project/cache                     2.0.1   Cache library
sonata
-project/core-bundle               3.18.0  Symfony SonataCoreBundle (abandoned)
sonata
-project/datagrid-bundle           2.5.0   Symfony SonataDatagridBundle
sonata
-project/doctrine-extensions       1.6.0   Doctrine2 behavioral extensions
sonata
-project/doctrine-orm-admin-bundle 3.17.1  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata
-project/easy-extends-bundle       2.5.0   Symfony SonataEasyExtendsBundle
sonata
-project/exporter                  2.2.0   Lightweight Exporter library
sonata
-project/user-bundle               4.5.2   Symfony SonataUserBundle



In Admin class I set field 'signatureDate' as editable

protected function configureListFields(ListMapper $listMapper) {
...
$listMapper
...

->add('signatureDate', null, [
               
'editable' => true,
               
'template' => 'signatureDate.html.twig',

           
]);



}


end customize template in signatureDate.html.twig when data value is not set

{% extends '@SonataAdmin/CRUD/base_list_field.html.twig' %}

{% block field %}
   
{% apply spaceless %}
   
{% if value is empty %}
       
<button type="button" class="btn btn-sm">Date</button>
    {% else %}
        {% set options = field_description.options %}
        <time datetime="{{ value|date('d-m-Y', 'UTC') }}" title="{{ value|date('d-m-Y', 'UTC') }}">
            {{ value|date(options.format|default('d-m-Y'), options.timezone|default(null)) }}
        </
time>
   
{% endif %}
   
{% endapply %}
</script>
{% endblock %}


Fields of admin interface look like this
and when click on date or button pops up a datepicker window:

I looked through the manuals and searched the internet, but I did not find a guide to customize the popuped datepicker window for editable data field in list view.

1) How to set language for popuped datepicker window ?
2) How to set a calendar on specific date (not current)? 

Thanks
Reply all
Reply to author
Forward
0 new messages