0

It's possible on symfony in formbuilder to create a new field if I select a X choice from a select?

I have this:

    $builder
        ->add('tipo', 'choice', array(
            'label'=>'Tipo de material:',
            'choices' => array(
                'file'   => 'Archivo descargable',
                'link' => 'Link',
                'test' => 'Test de evaluación',
                'video' => 'Video',
            ),
            'multiple' => false,
            'required' => true,
        ));

And I want this: if the user select "test" option (before sumit) add new field:

->add('newfield')

Thanks a lot!

Karmo
  • 383
  • 1
  • 3
  • 13
  • 1
    You cannot do this with PHP because the page has already been generated. You need to use JavaScript to dynamically add a new field as the user makes a selection. If you search for *"chained select menu"* you will find hundreds of posts and tutorials. Here is one which looks comprehensive: http://stackoverflow.com/questions/20789049/jquery-javascript-chained-select-tutorial-with-fiddle – BadHorsie Feb 28 '17 at 15:44
  • thanks a lot @BadHorsie! i'm going to JS now! – Karmo Feb 28 '17 at 15:52

0 Answers0