问题
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