SonataAdmin - sonata_type_choice_field_mask

hi all,

            ->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()

      

Here I am showing a list with options such as "GI" or "FI". A different list is displayed depending on the selection. List of companies. But always, depending on the choice, the list of companies that need to be filtered. I would like to see a company whose query field changes depending on whether billManagement is selected, "FI" or "GI".

I tried this but it doesn't 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()

      

early

Julien

ps: sorry for my english!

+2


source to share


1 answer


I achieved what I wanted. I just add two fields not showing



            ->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
        ))

      

+1


source







All Articles