Sonataadminbundle: Checkbox labels NOT showing with Bootstrap SF2.6 form theme

Created on 18 Dec 2014  路  12Comments  路  Source: sonata-project/SonataAdminBundle

Hello.

I enable this config with SF2.6 and Sonata Admin 2.3, then checkbox labels are not showing in forms.

# app/config.yml
twig:
    form:
        resources:
            - "bootstrap_3_layout.html.twig"

Most helpful comment

I encountered the same problem today.

It looks like the problem is 2-step:
1) block "checkbox_row" from "bootstrap_3_layout.html.twig" takes precedence over block "form_row" from "form_admin_fields.html.twig"
2) block "checkbox_label" from "bootstrap_3_layout.html.twig" takes precedence over block "form_label" from "form_admin_fields.html.twig"

To solve this problem I used additional/custom templates for sonata admin forms by adding to config:

sonata_doctrine_orm_admin:
    templates:
        form:
            - AppBundle:Admin:my_form_admin_fields.html.twig

and overridden problematic templates (appeding them to "form_admin_fields.html.twig" from sonata admin bundle whould be a possible work around for this problem, but maybe there are some better ones?)

{% extends 'SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig' %}

{% block checkbox_row -%}
    {{ block('form_row') }}
{%- endblock checkbox_row %}

{% block checkbox_label %}
    {{ block('form_label') }}
{% endblock checkbox_label %}

All 12 comments

I encountered the same problem today.

It looks like the problem is 2-step:
1) block "checkbox_row" from "bootstrap_3_layout.html.twig" takes precedence over block "form_row" from "form_admin_fields.html.twig"
2) block "checkbox_label" from "bootstrap_3_layout.html.twig" takes precedence over block "form_label" from "form_admin_fields.html.twig"

To solve this problem I used additional/custom templates for sonata admin forms by adding to config:

sonata_doctrine_orm_admin:
    templates:
        form:
            - AppBundle:Admin:my_form_admin_fields.html.twig

and overridden problematic templates (appeding them to "form_admin_fields.html.twig" from sonata admin bundle whould be a possible work around for this problem, but maybe there are some better ones?)

{% extends 'SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig' %}

{% block checkbox_row -%}
    {{ block('form_row') }}
{%- endblock checkbox_row %}

{% block checkbox_label %}
    {{ block('form_label') }}
{% endblock checkbox_label %}

@Axinet it works :+1: thx

Work for me too but the label is not on the checkbox line anymore

Be careful. @Axinet workaround doesn't show error messages (if errors exist in checkbox field).

Also came across this problem. For now I added
{% form_theme form 'bootstrap_3_layout.html.twig' %}

in all my normal forms.

Is this supposed to be fixed in future versions though?

It works for me too. Any chance for a fix in the next release?

:+1:

+1

Hello again @OskarStark, after update to this commit I think that this is not a good solution because we have 2 different scenes. We must consider when the form is embedded or not.

With @Axinet workaround you obtain this form templates (right for me):
captura de pantalla 2016-03-10 a les 11 18 34

But now I've got this forms, so I think that it's quite awful:
captura de pantalla 2016-03-10 a les 11 12 22

Hi @OskarStark, did you check my last msg?

@davidromani i think we can, but imo the first step is done now and the label looks nicer

in case of the collections/embedded we need to add another fix.
@vincenttouzet can you check this please?

I've created a new pull request to fix these bugs : https://github.com/sonata-project/SonataAdminBundle/pull/3672

Was this page helpful?
0 / 5 - 0 ratings