4

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?

Stiff Roy
  • 124
  • 1
  • 14

1 Answers1

1

You can do it with this sonata type. Have a look at this link, he had the same issue and resolved it :

SonataAdmin - sonata_type_choice_field_mask

KHALDOUN
  • 627
  • 5
  • 2
  • Hi, Thanks for your answer. But I think you did not get my main point. I cannot use a `choise_filed_mask` because al the values for my choice comes from the values of the entity and have to use `sonata_type_model` to get the results. – Stiff Roy Jul 22 '17 at 21:48