2014-07-18 4 views
4

엔티티 필드가 내 양식에 있습니다. 이 필드는 다음과 같습니다.Symfony 2 엔티티 필드 속성

->add('user', 'entity',array(
           'class' => 'Elearning\SiteBundle\Entity\User', 
           'property' => 'name', 
           'multiple' => true, 
           'expanded' => true, 
           'required' => true, 
           'label' => 'Użytkownicy ', 
           'attr' => array('class' => 'userFiledCollection'), // this not working. It set class to parent div. I want to have this class in checkboxes. 
           'query_builder' =>function(EntityRepository $er) { 
                return $er 
                 ->createQueryBuilder('u') 
                 ->where('u.isActive = 1'); 
                 }, 
         ) 
        ) 

내가 원하는 것은이 필드에 의해 렌더링 된 모든 확인란에 클래스 속성을 설정하는 것입니다. 내가 어떻게 할 수 있니?

+0

모든 체크 박스에 같은 클래스? 정말로해야하니? CSS를 이용한 경험 법칙 : 모든 요소에 동일한 클래스를 부여하면 잘못된 결과가 발생합니다. 예를 들어 자손 선택자를 사용하여 스타일을 지정할 수 있습니다 :'.userFiledCollection input [type = checkbox] {...}' – RoToRa

답변

1

빌드 인 솔루션이 없습니다. this issue을 참조하십시오.

가능한 솔루션 - Form theming 사용

{% form_theme form _self %} 

{% block checkbox_widget %} 
    {% spaceless %} 
     {% set attr = attr|merge({'class': 'userFiledCollection'}) %} 
     <input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} /> 
    {% endspaceless %} 
{% endblock checkbox_widget %} 

{% block body %} 
    {{ form(form) }} 
{% endblock %} 
+0

고마워요. :) – matterix

관련 문제