symfony 选择表格类型

vh0rcniy  于 2023-05-29  发布在  其他
关注(0)|答案(1)|浏览(142)

我有一个Symfony应用程序,它具有以下形式:

$builder->add('test', ChoiceType::class, [
                 'choices' => ['a' => 1, 'b' => 2],
                 'multiple' => false,
                 'mapped' => false,
                 'expanded' => true,
            ]);

我用{{ form_widget(form.test)}}显示它,我得到:

<div id="task_test">
    <div class="form-check">
        <input type="radio" id="task_test_0" name="task[test]" required="required" class="form-check-input" value="1">
        <label class="form-check-label required" for="task_test_0">a</label></div>
    <div class="form-check">
        <input type="radio" id="task_test_1" name="task[test]" required="required" class="form-check-input" value="2">
        <label class="form-check-label required" for="task_test_1">b</label>
    </div>
</div>

我想得到这个HTML代码:

<div id="task_test">
    <div class="form-check d-inline-block custom-control custom-radio mr-1">
        <input type="radio" id="task_test_0" name="task[test]" required="required" class="form-check-input custom-control-input" value="1">
        <label class="form-check-label required custom-control-label" for="task_test_0">a</label></div>
    <div class="form-check d-inline-block custom-control custom-radio">
        <input type="radio" id="task_test_1" name="task[test]" required="required" class="form-check-input custom-control-input" value="2">
        <label class="form-check-label required custom-control-label" for="task_test_1">b</label>
    </div>
</div>
juud5qan

juud5qan1#

这将不是你想要的一样,但至少它接近它

$builder->add('test', ChoiceType::class, [
    'choices' => [
        'a' => 1,
        'b' => 2,
    ],
    'multiple' => false,
    'mapped' => false,
    'expanded' => true,
    'row_attr' => [
        'class' => 'd-inline-block custom-control custom-radio mr-1',
    ],
    'label_attr' => [
        'class' => 'custom-control-label',
    ],
    'choice_attr' => [
        'class' => 'custom-control-input',
    ],
]);

如果您想要精确html输出,那么您必须编辑您的供应商模板

相关问题