I have a very simple problem and I think it is also very common. My sonata admin configureFormFields function looks like:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('status', 'sonata_type_model', array(
'required' => true,
'btn_add' => false,
'expanded' => true,
)
->add('activeReason', 'hidden')
->add('inactiveReason', 'hidden')
->add('onHoldReason', 'hidden')
;
}
The 'status' entity has the __toString() method defined and the values are:
- Active
- Inactive
- Hold
What I want is, if I select 'Active' from the status, the 'activeReason' form field should be shown, whereas selecting the 'Inactive' will hide the other 2 reason field and just show the 'inactiveReason' field and so with the Hold selection (it will hide the other 2 and just show the 'onHoldReason' form field).
I know it is possible with custom jQuery functions, but is there a SONATA ADMIN WAY or SYMFONY WAY? I am quite aware of the sonata form type sonata_type_choice_field_mask
which has to have an array of choices. Is there any way to combine this function or do something of this similar type?