Use a conditional statement when creating a form

Viewed 5718

I would like to use a conditional statement when creating a form in Symfony.

I am using a choice widget in general case. If the user selects the option "Other", I would like to display an additional text box widget. I suppose this can be done in javascript, but how can I still persist the data from 2 widgets into the same property in my entity?

I have this so far:

  $builder->add('menu', 'choice', array(
        'choices'   => array('Option 1' => 'Option 1', 'Other' => 'Other'),
        'required'  => false,
    ));
  //How to add text box if choice == Other ????

I was planing to use a DataTransfomer, but on 2 widgets??

1 Answers
Related