Skip to content Skip to sidebar Skip to footer

Symfony - Dynamic Drop Down Lists Not Working Only When Editing

First of all, I'm French, so I hope my english is not so bad ^^' I have a problem with Symfony3 and I don't know how to resolve it. I have a form with 3 drop down lists. 2 of theme

Solution 1:

Ok, so I found a solution, apparently the problem was in my javascript. For the attribute "data" in the Ajax request, I have to pass the value of the drop down list "Category". Then, when I run the Ajax request, it works fine. If I don't do that, like I said in my first message, the Ajax request fails because the "Category" value is set to null.

My new javascript :

$(document).ready(function() {
var agence = $('#sinistre_edit_agence');

/* Actualisation de la liste déroulante des centres en fonction de l'agence sélectionnée */
agence.change(function() {
    // Animation "Chargement en cours"toggleLoading();

    var form = $(this).closest('form');
    var data = {};
    data[agence.attr('name')] = agence.val();
    data[categorie.attr('name')] = categorie.val(); // FIX : the category value

    $.ajax({
        url : form.attr('action'),
        type: form.attr('method'),
        data : data, // Now, contains my "Agence" value and "Category" valuesuccess: function(html) {
            $('#sinistre_edit_centre').replaceWith(
                $(html).find('#sinistre_edit_centre')
            );
            toggleLoading();
        },
        error: function(error) {
            console.error(error);
            toggleLoading();
        }
    });
});

});

I have to admit that I don't really understand why the third drop down list, which has nothing to do with my 2 others related drop down lists, was the problem !

Post a Comment for "Symfony - Dynamic Drop Down Lists Not Working Only When Editing"