Symfony form & Ajax

I am working on Symfony 4.4.

To refresh a table, users select three options with an input:

  • InProgress
  • Finished
  • All

Then they must press a validate button.

I want to improve the use of this page by automating the refresh of the table.

Currently on my model I have AJX which allows me to retrieve the value of my entry:

   <script>
    $(document).on('change', '#campagnes_tel_isAttending', function () {
        $('#flash').remove();
        let $field = $(this)
        let $preselect = $('#campagnes_tel_isAttending')
        let $form = $field.closest('form')
        let data = {}
        data[$field.attr('name')] = $field.val()
        console.log(data)
        // On soumet les données
        // $.post($form.attr('action'), data).then(function (data) {
        //     // On récupère le nouveau <select>
        //     $('#planningsms_client_label').val($(data).find('#planningsms_client option:selected').text());
        //     let $input = $(data).find(target)
        //     // On remplace notre <select> actuel
        //     $(target).replaceWith($input)
        // })
    });
</script>

I am now stuck because I cannot figure out how to get information back to my Controller, allowing me to modify a PreSelect variable with the value of the input and change the structure of the SQL query.

Create a route? Call a route in an Ajax POST?
Use this route in my Controller?

I think it’s more or less that, but on the other hand I have no idea how to implement it.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *