Symfony2 how to render Checkboxes?

前端 未结 3 578
醉话见心
醉话见心 2021-01-03 10:18

I have a formbuilder form with a multiple choice list of countries. When I render them on my form like this:

{{ form_widget(edit_form.countries) }}
<         


        
3条回答
  •  梦谈多话
    2021-01-03 11:05

    As Kuba has said in his answer this sounds partly like a CSS question. Semantically speaking injecting something like a
    tag doesn't have much meaning but you can do that if you wish by following the documents in Kuba's answer.

    If you wish to write some CSS to get those elements to display line by line you can use this against symfony's default output:

    input, label {
        float: left;
    }
    
    input {
        clear: left;
    }
    

    Of course this will actually cause all input and label tags to float left which might not be suitable to you so you can a) wrap your checkboxes in another div and use a css sub-selector like .checkboxes input, .checkboxes label or b) apply a custom css class to your widgets using:

    {{ form_widget(form.name, { 'attr': {'class': 'foo'} }) }}
    

    and the CSS would be the same but instead of input you'd have .foo.

提交回复
热议问题