phpformssymfonycustom-controlssymfony-forms

Symfony2 forms ignores attributes in custom fields when same defined in buidler


When I define attributes in form builder and same attributes as default in custom field the other are ignored. In form builder I have:

    $builder
            ->add('validityOfADecisionOnDisability', new JQDateType(), array(
                'attr' => array(
                    'rel' => 'permanent',
                )
            ))

and custom field

class JQDateType extends AbstractType {

public function getDefaultOptions(array $options)
{
    return array(
        'widget' => 'single_text',
        'format' => 'yyyy-MM-dd',
        'attr' => array(
            'class' => 'datepicker'
        )
    );
}

and it renders html

<input type="text" rel="permanent" required="required" 
  name="profile[validityOfADecisionOnDisability]" 
  id="profile_validityOfADecisionOnDisability">

without class. But when I add class to attributes in builder

    $builder
            ->add('validityOfADecisionOnDisability', new JQDateType(), array(
                'attr' => array(
                    'rel' => 'permanent',
                    'class' => 'datepicker',
                )
            ))

eevrything works as expected. How should I define attributes in JQDateType() ? I tried to use array_merge() and array_merge_recursive() in JQDateType::getDefaultOptions() but it didn't help.


Solution

  • This was a bug that is fixed in Symfony 2.1.