0

有没有办法通过'attr'和'constraints',以便它们适用于生日/日期对象的日,月或年?

这是我目前拥有的,但它们只适用于整个 div

$form = $app['form.factory']->createBuilder('form')
    ->add(
        'registerDOB',
        'birthday',
        array(
            'widget' => 'text',
            'input' => 'string',
            'label' => 'Date of birth',
            'format' => 'ddMMyyyy',
            'error_bubbling' => true,
            'attr' => array(
                'day' => array(
                    'class' => 'form-input form-register-postcode',
                    'data-required' => 'true',
                    'placeholder' => '',
                    'data-error-message' => ''
                )
            ),
            'constraints' => array(
                new Assert\NotBlank(
                    array(
                        'message' => 'DOB must not be blank.',
                    )
                ),
            ),
        )
    )

通过 {{ form_widget(form.registerDOB) }} 调用时的输出

<div data-error-message="" placeholder="" data-required="true" class="form-input form-register-postcode" id="form_registerDOB">
    <input type="text" required="required" name="form[registerDOB][day]" id="form_registerDOB_day" class="parsley-validated">
    <input type="text" required="required" name="form[registerDOB][month]" id="form_registerDOB_month" class="parsley-validated">
    <input type="text" required="required" name="form[registerDOB][year]" id="form_registerDOB_year" class="parsley-validated">
</div>
4

0 回答 0