0

I want to implement onchange ajax request in sonata admin bundle in Symfony2.I want to create a cascading dropdown.if i select option from a drop down then according to the value of the dropdown, the next dropdown will automatically populate the value.

Any idea will be appreciated ..

Awlad Liton
  • 9,366
  • 2
  • 27
  • 53
Aman Varshney
  • 820
  • 1
  • 9
  • 26

1 Answers1

0

I think you just have to override standard_layout.html.twig layout template and load your custom JS file.

Note: Maybe you just have to override the CRUD edit template and not all the layout. Create the file and specify it in your SonataAdminBundle configuration:

sonata_admin:
    templates:
        edit: YourCustomBundle:CRUD:edit.html.twig

Then, override the javascript block to add your JS file:

{% block javascripts %}
    {{ parent() }}
    <script src="{{ asset('bundles/mycustombundle/myfile.js') }}" type="text/javascript"></script>
{% endblock %}

Finally, you just have to add a listener on your first dropdown field and make an AJAX request (when your selected value changed) that will point on a custom controller and return your second dropdown values.

I think this should be ok.