Reputation: 551
I would like how could a make that my first option of an EntityType is NULL.
I've tried with a placeholder, but is not possible because when I try to register the form it obligate to select a different option which is not the place holder.
I'm trying something like this:
->add('idacademicprogram', EntityType::class, array(
"class" => 'AppBundle:Academicprogram',
'placeholder' => 'Choose an option',
"attr"=>array(
"class" => "form-iduser form-control",
"required" => false
)))
Upvotes: 6
Views: 9569
Reputation: 176
You can fix by adding data or empty_data
data will contain the value of list for example (a=>1, b=>22, c=33) then the code will be:
->add('idacademicprogram', EntityType::class, array(
"class" => 'AppBundle:Academicprogram',
'placeholder' => 'Choose an option',
'required' => false,
'data' => <Value>,
"attr"=>array(
"class" => "form-iduser form-control"
)))
and empty_data it will contain null value code will be like this:
->add('idacademicprogram', EntityType::class, array(
"class" => 'AppBundle:Academicprogram',
'placeholder' => 'Choose an option',
'required' => false,
'empty_data' => '',
"attr"=>array(
"class" => "form-iduser form-control"
)))
Upvotes: 2
Reputation: 551
Ok i fixed changing required on global array, not on attr.
Would be something like this:
->add('idacademicprogram', EntityType::class, array(
"class" => 'AppBundle:Academicprogram',
'placeholder' => 'Choose an option',
'required' => false,
"attr"=>array(
"class" => "form-iduser form-control"
)))
Upvotes: 9