formssymfonymultiple-choicechoicefield

Choices as choice option in choice field Type in symfony2


Maybe is a little confusing question but here is an explanation by the code:

is there a way to do something like this?

$builder->add(
            'doYouWantToEnterData',
            'choice',
            array(
                'choices'   => array(
                    0   => 'no',
                    1   => 'choices_name',
                ),
            ),
          'extend' =>true 
        )
        ->add(
            'choices_name',
            'choice',
            array(
                'choices'   => array(
                    0   => 'text_input_name',
                    1   => 'select_box_name',
                ),
            ),
          'extend' =>true 
        )
        ->add('text_input_name' )
        ->add(
            'select_box_name',
            'choice',
            array(
                'choices'   => array(
                    0   => 'choice_1',
                    1   => 'choice_2',
                ),
            ),
        );

as you can see the choices_name is the option in the option named doYouWantToEnterData and options in the choices_name are text_input_name and select_box_name


is there a way to create this kind of stuff in the FormType class ??

:)


Solution

  • No. There is no such functionality bundled in the standart form component. The best way of doing this is to create custom form type + some JS code to show/hide necessary fields. And i suggest you to watch this video (there is an example of similiar problem with choice and optional text).