Here's the beginning of the description for my problem (made the
mistake to open this thread in the wrong group, sorry for that).

http://groups.google.com/group/jquery-dev/browse_thread/thread/8c2edf79fdebf61e

Unfortunatelly, I cannot provide an online test page. But I can keep
on describing error alerts, and IE's behaviour.

First, here's the code I came up with today :

$(document).ready(function(){


    /*
     * BOF // Fonction pour garder la session active
     */
    var sessionKeepAlive = 1000 * 50;
    function keepSessionAlive(){
        $.ajax({
            url: '/actions/keepAlive',
            success: function(data){
                setTimeout(function(){
                    keepSessionAlive();
                }, sessionKeepAlive);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                setTimeout(function(){
                    keepSessionAlive();
                }, sessionKeepAlive);
            }
        });
    }
    keepSessionAlive();

    /*
     * EOF // Fonction pour garder la session active
     */

    /*
     * BOF // Fonction de gestion / validation/ Submit du formulaire
de coordonnées de facturation
     */
         $("#formulaireFinalCreationCompte input").live("change", function(){
        $("#formulaireFinalCreationCompte").validate({
            errorPlacement: function(error, element){
                error.appendTo(element);
            },
            rules: {
                facturationCivilite: "required",
                facturationNom: "required",
                facturationPrenom: "required",
                facturationAdresse1: "required",
                facturationCodePostal: {
                    required: true,
                    rangelength: [5, 5],
                    number: true
                },
                facturationVille: "required",
                facturationTel: {
                    number: true,
                    required: true
                },
                facturationEmail: {
                    required: true,
                    email: true
                }
            },
            submitHandler: function(form){
                var action = $(form).attr('action');
                var data = $(form).serialize();
                $.ajax({
                    cache: false,
                    url: action,
                    data: data,
                    success: function(reponse){
                        $('#coordonneesFacturation').empty();
                        $('#coordonneesFacturation').html(reponse);
                    }
                });
            }
        });
                if ($("#formulaireFinalCreationCompte").valid()){
                        $("#formulaireFinalCreationCompte").submit();
                }
        });
    /*
     * EOF // Fonction de gestion / validation/ Submit du formulaire
de coordonnées de facturation
     */



     /*
     * BOF // Fonction de génération 'otf' du panier dynamique (objet
JSON parsé)
     */
      function generationTable(json){
                var reponse = eval('(' + json + ')');
                $.each(reponse.articles,function(i,article) {
                        var articleRow = $("<tr>").addClass
("ligneArticlePrincipal").appendTo("#panierDetail tbody");
            $("<td>").addClass("libelleArticlePrincipal").text
(article.libelle).appendTo(articleRow);

            var prixAffiche = parseInt(article.prixAffiche);
            if (prixAffiche != 0) {
                $("<td>").addClass('prixTotalLigne').text
(article.prixAffiche).appendTo(articleRow);
            }
            else {
                $("<td>").html('<input type="text"
id="prixUnitaireArticle" value="0" name="prixCommandeCarte"/
>').appendTo(articleRow);
            }
            var inputText = $("<td>").html('<input type="text"
id="quantitePrincipal" class="quantite" value="' + article.quantite +
'" name="quantiteLigneCommande(' + article.id + ')"/>').appendTo
(articleRow);
            var inputHidden = $("<input type=\"hidden\"/>").attr
('value', article.id).attr('id', 'articlePrincipalCourantId').attr
('name', 'articlePrincipalCourantId');

            var remiseLigneArticle = $("<td>").addClass
('remiseLigneArticle').html('<span id="remiseLigneArticle">' +
article.montantRemise + '</span>').appendTo(articleRow);

            $(inputHidden).appendTo(inputText);
            var prixTotalArticle = "00,00";
            if (article.prixTotal != "") {
                prixTotalArticle = article.prixTotal;
            }
            var totalLigneArticle = $("<td>").addClass
('prixTotalLigne').html('<span id="totalArticle">' + prixTotalArticle
+ '</span>').appendTo(articleRow);
        });

            $("tfoot td.prixTotalLigne").html(reponse.totalPanier);

    }

        /*
         * BOF  Support du live('change')
         */
        var articleEnCoursVal ;
        $(".quantite").live("focus",function(){
                articleEnCoursVal = parseInt($(this).val());
        });

    $(".quantite").live("change", function(){
        var formulaire = $(this).parents("form:first");
        var action = $(formulaire).attr('action');

        action = $(formulaire).attr('action');
        var nouvelleValeur = parseInt($(this).val());

        var articleId = $(this).next('input:hidden').val();
        var quantite = $(this).val();
        var data;
        if (articleEnCoursVal != 0 && articleEnCoursVal !=
nouvelleValeur) {
            action = '/actions/actualierPanierCommande';
            data = '';
            $("input.quantite").each(function(){
                data += $(this).attr('name');
                data += "=";
                data += $(this).val();
                data += "&";
            })
        }
        else {
            data = "articleId=";
            data += articleId;
            data += "&";
            data += "quantite=";
            data += quantite;
            if ($(this).parents("tr:first").find
('#prixUnitaireArticle').length != 0) {
                var prixUnitaireArticle = $(this).parents
("tr:first").find('#prixUnitaireArticle').val();
                data += "&";
                data += "prixUnitaireArticle=";
                data += prixUnitaireArticle;
            }
        }
        $.ajax({
            url: action,
            data: data,
            cache: false,
                        contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(reponseJSON){
                $("#panierDetail tbody").empty();
                generationTable(reponseJSON);
            }
        });
    });

        /*
         * EOF live(change)
         */


    var adresseDelivraison = "/actions/commande/
adresseDestinataireFormulaireCommande";

    function rafraichirCoordonnesLivraison(){
        $.ajax({
            cache: false,
            url: adresseDelivraison,
            success: function(reponseFormulaire){
                $("#coordoneesLivraison").empty();
                                
$('#coordoneesLivraison').html(reponseFormulaire);
                gestionCheckboxesLivraison();
            }
        });
    }

    function gestionCheckboxesLivraison(){
        if ($("#beneficiaire").is(':checked')) {
            $("#renseignementLivraison").show();
            $("#renseignementAcheteur").hide();
            $("#domicile").attr('checked', false);
            $(".lieuLivraison").html("Au domicile du bénéficiaire");
        }

        if ($("#domicile").is(':checked')) {
            $("#renseignementAcheteur").show();
            $("#renseignementLivraison").hide();
            $("#beneficiaire").attr('checked', false);
            $(".lieuLivraison").html("A domicile");
        }

        $("#beneficiaire").click(function(){
            if ($(this).is(':checked')) {
                $("#renseignementLivraison").show();
                $("#renseignementAcheteur").hide();
                $("#domicile").attr('checked', false);
                $(".lieuLivraison").html("Au domicile du
bénéficiaire");
            }
            else {
                $(this).attr('checked', true);
                $("#renseignementLivraison").hide();
            }
        });

        $("#domicile").click(function(){
            if ($(this).is(':checked')) {
                $("#renseignementAcheteur").show();
                $("#renseignementLivraison").hide();
                $("#beneficiaire").attr('checked', false);
                $(".lieuLivraison").html("A domicile");
            }
            else {
                $(this).attr('checked', true);
                $("#renseignementAcheteur").hide();
            }
        });
    }


    $("#adresseLivraison input").live('change',function(){
                $("#adresseLivraison").validate({
                                         errorPlacement: function(error, 
element){
                        error.appendTo(element);
                    },
                    rules: {
                        livraisonEmail: {
                            required: "#beneficiaire:checked",
                            email: true
                        },
                        livraisonCivilite: {
                            required: "#beneficiaire:checked"
                        },
                        livraisonNom: {
                            required: "#beneficiaire:checked"
                        },
                        livraisonPrenom: {
                            required: "#beneficiaire:checked"
                        },
                        livraisonAdresse1: {
                            required: "#beneficiaire:checked"
                        },
                        livraisonCodePostal: {
                            required: "#beneficiaire:checked"
                        },
                        livraisonVille: {
                            required: "#beneficiaire:checked"
                        },
                        livraisonEmail: {
                            required: "#beneficiaire:checked"
                        },
                        livraisonTel: {
                            required: "#beneficiaire:checked"
                        },
                        dateNaissance: {
                            required: "#beneficiaire:checked",
                            date: true
                        },
                        dateEnvoyerCodeActivation: {
                            required: "#beneficiaire:checked",
                            date: true
                        }
                    },
                    submitHandler: function(form){
                        var action = "/actions/commande/
enregistrerCoordonneesLivraisonCommande";
                        var data = $(form).serialize();
                        $.ajax({
                                                        cache: false,
                            url: action,
                            data: data,
                            success: function(reponseJSON){
                                $('#coordoneesLivraison').empty();
                                $('#coordoneesLivraison').html
(reponseJSON);
                                gestionCheckboxesLivraison();
                            }
                        });
                    }
                });

                if ($("#adresseLivraison").valid()) {
                    $(this).submit();
                }
    });


        /*
         * BOF // ensembles de fonctions ajax pour charger les differents
formulaires de l'interface
         */

        //
        //------Le chargement AJAX du panier
        //
        if ($("table#panierDetail").length > 0) {
                $.ajax({
                        cache: false,
                        url: "/actions/formulaireArticles",
                        data: "referenceVitrine=CARTEBESTCADEAUX",
                        success: function(reponse){
                                generationTable(reponse);
                        }
                });
        }

        //
        //------Le chargement AJAX des coordonnées de facturation
        //
    if ($('#coordonneesFacturation').length > 0) {
        $.ajax({
            cache: false,
            url: "/actions/commande/
editerCoordonneesFacturationCommande",
            success: function(reponseFormulaireFacturation){
                $('#coordonneesFacturation').html
(reponseFormulaireFacturation);
            }
        });
    }

        //
        //------Le chargement AJAX des coordonnées de livraison
        //
    if ($("div#coordoneesLivraison").length > 0) {
        rafraichirCoordonnesLivraison();
    }
});

And here's a basic copy/paste of the Json objet forwarded by my Struts
action :

{

        "totalPanier":"288,00&euro;",

        "articles": [
                                                        {
                                                                
"id":"8a8b8d2e256d72fc01256d79de660017",
                                                                
"prixAffiche":"76,00",
                                                                "quantite" : 
"3",
                                                                
"libelle":"Carte BEST CADEAUX à montant variable",
                                                                "montantRemise" 
:"",
                                                                
"prixTotal":"228,00 &euro;"
                                                        },

                                                        {
                                                                
"id":"8a8b8d632481567f01248156fac90009",
                                                                
"prixAffiche":"0,00",
                                                                "quantite":"0",
                                                                
"libelle":"Carte BEST CADEAUX à montant variable",
                                                                "montantRemise" 
:"",
                                                                
"prixTotal":"00,00&euro;"
                                                        },

                                                        {
                                                                
"id":"8a8b8d2e256d72fc01256d7babd30018",
                                                                
"prixAffiche":"80,00",
                                                                "quantite" : 
"1",
                                                                
"libelle":"Carte BEST CADEAUX 80 Euros",
                                                                "montantRemise" 
:"20,00",
                                                                
"prixTotal":"60,00 &euro;"
                                                        },

                                                        {
                                                                
"id":"8a8b8d632481567f012481570578000f",
                                                                
"prixAffiche":"50,00",
                                                                "quantite":"0",
                                                                
"libelle":"Carte BEST CADEAUX 50 Euros",
                                                                "montantRemise" 
:"",
                                                                
"prixTotal":"00,00&euro;"
                                                        },

                                                        {
                                                                
"id":"8a8b8d632481567f012481570549000e",
                                                                
"prixAffiche":"30,00",
                                                                "quantite":"0",
                                                                
"libelle":"Carte BEST CADEAUX 30 Euros",
                                                                "montantRemise" 
:"",
                                                                
"prixTotal":"00,00&euro;"
                                                        },

                                                        {
                                                                
"id":"8a8b8d632481567f012481570364000d",
                                                                
"prixAffiche":"15,00",
                                                                "quantite":"0",
                                                                
"libelle":"Carte BEST CADEAUX 15 Euros",
                                                                "montantRemise" 
:"",
                                                                
"prixTotal":"00,00&euro;"
                                                        },

        ]
}

So basically, the last 3 ajax calls in the bottom of the script are
here to 'initialize' the interface, loading each form separattely.
This seems to work well.
As soon as these forms are loaded, the use of the .live('change')
event handler allows forms to auto-validate themselves, to finally,
after validating, auto-submitting.
Tracing ajax calls in FF shows everything works fine.
But as soon as you enter values in form using the $(".quantite")
inputs, FF fires the ajax request, with success, but returns me a
"missing ] after element list ([object Object])". The stranger thing
is, my Json is always generated using the same jsp, and always gives
the same formatted result as seen above...

Any ideas ?

Reply via email to