Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2 form field radio required=false?

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.

like image 386
user2156980 Avatar asked Nov 30 '22 00:11

user2156980


1 Answers

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
        ]);
like image 50
user2156980 Avatar answered Dec 15 '22 12:12

user2156980