symfony - Time picker (no date) in a Sonata-admin form -
i'm upgrading symfony project's sonata admin usage, sonata-admin 2.2 2.3, part of upgrading overall project symfony 2.7.
we have number of 'time' fields (that is, defined in doctrine "time", no meaningful date component.)
in sonata-admin 2.2 formmapper definition simple:
$formmapper ->tab('tab.general') ->add('start', null, array('label' => 'label.start') ->end()
and gave layout of "half-form-width" hour , minute selection boxes, side side, in form:
but sonata-admin 2.3 showing them on 2 full lines:
which not nice or useable.
so, should setting same rendering?
i've tried using 'sonata_type_datetime_picker' insistent on displaying date. these fields not have date. there seems no equivalent picking time.
had same issue , solved adding own css file overrides.
1) add class form field
->add('start', 'time', array( 'attr' => array('class' => 'fixed-time') ))
2) create new css file in bundle under resources/public/css/override.css overrides fixed-time class
for example:
.fixed-time .select2-container { width: auto !important; }
3) somewhere in bundle (resources/views) create new template called standard_layout.html.twig , override sonata template + add newly created css file (remember call parent() first, load sonata code first).
{% extends 'sonataadminbundle::standard_layout.html.twig' %} {% block stylesheets %} {{ parent() }} <link rel="stylesheet" href="{{asset('bundles/yourbundle/css/override.css')}}" type="text/css" media="all"/> {% endblock %}
4) register standard_layout twig template sonata admin (in config.yml).
sonata_admin: templates: layout: yourbundle::standard_layout.html.twig
do not forget install new assets (assets:install) , clear cache (remove selected folder app/cache), otherwise not see change.
Comments
Post a Comment