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 ..
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.