SonataAdmin - sonata_type_choice_field_mask

亡梦爱人 提交于 2019-12-11 01:15:22

问题


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

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

thank you in advance

Julien

ps: sorry for my english !


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


来源:https://stackoverflow.com/questions/36840963/sonataadmin-sonata-type-choice-field-mask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!