EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Switch Choice content based on selection

Open KDederichs opened this issue 1 year ago • 3 comments

Short description of what this feature will allow to do: Similar to https://ux.symfony.com/demos/live-component/dependent-form-fields when you switch the input of one field, the options on the other ones get updated.

Example of how to use this feature

For config something simple like this would probably work:

     ChoiceField::new('foo'),
     ChoiceField::new('bar')
          ->setDependsOn('foo')
          ->setDependantOptionProvider(function ($fooValue) {
               // fancy code
              return [
                 'label' => 'value'
             ]
          })

and then in the frontend it'd update the choices for bar everytime Foo changes

KDederichs avatar Nov 15 '23 14:11 KDederichs

For anyone stumbling on this in the meantime: https://github.com/EasyCorp/EasyAdminBundle/issues/4716#issuecomment-1824847531

That's my current solution, I feel it's a lot more convoluted than it needs to be though

KDederichs avatar Nov 23 '23 19:11 KDederichs

@KDederichs could you provide an example for tow chained filter that one depend on the other ?

ahmed-bhs avatar May 23 '24 14:05 ahmed-bhs

Not sure what you mean? If it's form fields that change based on the previous one look at the comment I posted. If it's for filters (like easy admin filters) no clue, never looked into how you'd do it there.

KDederichs avatar May 23 '24 14:05 KDederichs