Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EntityType Symfony set default as null

Tags:

forms

php

symfony

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
            )))
like image 278
KaSkuLL Avatar asked Sep 09 '26 08:09

KaSkuLL


1 Answers

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"
            )))
like image 138
KaSkuLL Avatar answered Sep 11 '26 01:09

KaSkuLL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!