Symfony 2 form field radio required=false?

user2156980 picture user2156980 · Nov 4, 2013 · Viewed 13.4k times · Source

This is part of my entity class :

/**
 * @var integer
 *
 * @ORM\Column(name="student", type="integer", nullable=true)
 */
private $student;

This part of my form class :

 $builder
    ->add('student', 'choice', ['label'=> false,
    'expanded' => true,
    'choices' => (Array)new StudentEnum(),
   ])
        ;

Ad this is output :

<input id="xxxxx_0" type="radio" value="4" required="required" name="xxxxx[student]">
<label class="required" for="xxxxxV_student_0">Nie</label>

...

My problem is that my input tag should not have attribute "required" becouse I have set nullable=true in entity.

Answer

user2156980 picture user2156980 · Nov 4, 2013

The solution is required => false and empty_value => false

$builder
        ->add('student', 'choice', [
                'label'=> false,
                'expanded' => true,
                'choices' => (Array)new StudentEnum(),
                'required' => false,
                'empty_value' => false
        ]);