使用Bootstrap的Symfony-单选按钮切换

时间:2019-01-05 22:26:19

标签: symfony

使用Form类和Bootstrap 4 Form主题,如何切换单选样式按钮?

<div class="btn-group btn-group-toggle" data-toggle="buttons">
  <label class="btn btn-secondary active">
    <input type="radio" name="options" id="option1" autocomplete="off" checked> Active
  </label>
  <label class="btn btn-secondary">
    <input type="radio" name="options" id="option2" autocomplete="off"> Radio
  </label>
  <label class="btn btn-secondary">
    <input type="radio" name="options" id="option3" autocomplete="off"> Radio
  </label>
</div>

链接:interoperability

谢谢:)

1 个答案:

答案 0 :(得分:0)

在您的src / Form / Type / File_nameType.php文件中:

$builder
    ->add('your label name', Radio::class, array(
    'attr' => array('class' => 'btn-group btn-group-toggle')
       ))

然后在树枝模板中也可以添加标签类:

{{ form_label(form.name, 'Your name', {
       'label_attr': {'class': 'btn btn-secondary active'}
}) }}