php - Extraneous option field in Symfony2 form -
i'm using symfony version 2.5.4 , have builder looks this.
$builder->add('licensed', 'choice', array( 'choices' => array( 'n/a' => '--', 'yes' => 'yes', 'no' => 'no' ), 'required' => false, 'label' => 'somelabel', 'label_attr' => array('class' => 'font-bold'), 'attr' => array('class' => 'rounded') ) );
when render form get:
<select id="companyotherinformation_licensed" name="companyotherinformation[licensed]" class="rounded"> <option value=""></option> <-- not sure coming from. <option value="n/a">--</option> <option value="yes">yes</option> <option value="no">no</option> </select>
there's <option value=""></option>
have no idea how got there. can find out came , rid of it? symfony2 bug?
i've tried app/console cache:clear
, i'm still not able rid of it.
not bug:
http://symfony.com/doc/current/reference/forms/types/choice.html#empty-value
if leave empty_value option unset, blank (with no text) option automatically added if , if required option false:
so add: 'empty_value' => false
but think it, setting required = false implies that user not have select anything. options, have no choice. having required = true make more sense.
Comments
Post a Comment