2
    ->add('billManagement', 'sonata_type_choice_field_mask', array(
    'choices' => array(
        'FI' => 'FI',
        'GI' => 'GI'
    ),
    'map' => array(
        'FI' => array('company'),
        'GI' => array('company')
    ),
    'empty_value' => 'Mode de financement',
    'required' => true
))
->add('company')
->end()

I show here a list box with choices such as "GI" or "FI". Depending on the choice, another box list is displayed. A box Companies list. But always depending on the choice, the list of companies to be filtered. I would like to see a company whose query field changes depending on the choice of billManagement, "FI" or "GI".

I tried that but it does not work

    ->add('billManagement', 'sonata_type_choice_field_mask', array(
    'choices' => array(
        'FI' => 'FI',
        'GI' => 'GI'
    ),
    'map' => array(
        'FI' => $formMapper->add('company', 'sonata_type_model', array(
            'class' => 'AppBundle\Entity\User\Company',
            'query' => $companyFinance
        )),
        'GI' => $formMapper->add('company', 'sonata_type_model', array(
            'class' => 'AppBundle\Entity\User\Company',
            'query' => $company
        )),
    ),
    'empty_value' => 'Mode de financement',
    'required' => true
))
->end()
David Buck
  • 3,752
  • 35
  • 31
  • 35
Ju'
  • 31
  • 3

1 Answers1

1

I have achieved what I wanted to do. I just add two fields not mapped

    ->add('billManagement', 'sonata_type_choice_field_mask', array(
    'choices' => array(
        'FI' => 'FI',
        'GI' => 'GI'
    ),
    'map' => array(
        'FI' => array('companyFinance'),
        'GI' => array('company'),
),
    'empty_value' => 'Mode de financement',
    'required' => true
))
->add('companyFinance', 'sonata_type_model', array(
    'class' => 'AppBundle\Entity\User\Company',
    'query' => $companyFinance,
    'mapped' => false
))
->add('company', 'sonata_type_model', array(
    'class' => 'AppBundle\Entity\User\Company',
    'query' => $company,
    'mapped' => false
))
David Buck
  • 3,752
  • 35
  • 31
  • 35
Ju'
  • 31
  • 3