在Symfony3复选框的label属性上设置类

时间:2017-03-21 02:57:16

标签: symfony checkbox twig

我有一个symfony3项目,我通过twig向一些表单字段添加自定义类。对于复选框标签,这一切都正常除了。我的自定义类没有按预期在复选框的标签中显示。

编辑:添加我的表单构建器:

class ReferralFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('modality', EntityType::class, [
                'class' => Modality::class,
                'placeholder' => 'Choose modality',
                'choice_label' => 'name',
            ])
            ->add('referralFromDoctor', EntityType::class, [
                'class' => Doctor::class,
                'placeholder' => 'Choose a doctor:',
                'choice_label' => 'name',
            ])
            ->add('isFollowup', CheckboxType::class, [
                'label' => 'Follow up visit?',
            ])
            ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Referral::class
        ]);
    }
}

这是我的树枝模板:

{{ form_start(form) }}

<div id="js-order-wrapper">
    {{ form_label(form.modality, 'Type', { 'label_attr': {'class': 'js-hidden-row'} }) }}
    {{ form_widget(form.modality, { 'attr': {'class': 'js-hidden-row'} }) }}

    {{ form_label(form.referralFromDoctor, 'Ordering clinician', { 'label_attr': {'class': 'js-hidden-row'} }) }}
    {{ form_widget(form.referralFromDoctor, { 'attr': {'class': 'js-hidden-row'} }) }}

    {{ form_label(form.isFollowup, 'Follow up?', { 'label_attr': {'class': 'js-hidden-row'} }) }}
    {{ form_widget(form.isFollowup, { 'attr': {'class': 'js-hidden-row'} }) }}
</div>

{{ form_end(form) }}

这里是渲染的html:

<div id="js-order-wrapper">
    <label class="js-hidden-row control-label required" for="referral_form_modality">Type</label>
    <select id="referral_form_modality" name="referral_form[modality]" required="required" class="js-hidden-row form-control"><option value="">Choose modality</option></select>

    <label class="js-hidden-row control-label required" for="referral_form_referralFromDoctor">Ordering clinician</label>
    <select id="referral_form_referralFromDoctor" name="referral_form[referralFromDoctor]" required="required" class="js-hidden-row form-control"><option value="">Choose a doc</option></select

    <div class="checkbox">
        <label class="required">
            <input type="checkbox" id="referral_form_isFollowup" name="referral_form[isFollowup]" required="required" class="js-hidden-row" value="1" /> Follow up visit?
        </label>
    </div>
</div>

如您所见,类'js-hidden-row'已正确应用于字段的标签,但对于复选框,该类不会应用于标签。对我来说似乎是一个错误。

如果没有编写自定义代码块来呈现复选框,是否有更好的解决方案?

0 个答案:

没有答案