$(function() { $("#form_jp").show(); $("#form_erreur-js").hide(); $(".participant").each(function(i, participant) { $(".ajouter-participant", participant).click(function(e) { e.preventDefault(); $(participant).next().slideDown(400); $(".inner-bouton", participant).css("display", "none"); }); $(".supprimer-participant", participant).click(function(e) { e.preventDefault(); $(participant).slideUp(400, function() { $("select,input,textarea", participant).val(""); $("input[type='radio'], input[type='checkbox']", participant).prop("checked", false); $("select[id*='_atelier'] option", participant).removeAttr("disabled").show(); }); $(participant).prev().find(".inner-bouton").css("display", ""); }); $("select[id*='_atelier']", participant).change(function() { $("select[id*='_atelier'] option", participant).removeAttr("disabled").show(); $("select[id*='_atelier']", participant).each(function() { if($(this).val() != "") $("select[id*='_atelier']", participant).not(this).children("option[value='" + $(this).val() + "']").attr("disabled", "disabled").hide(); }); }).trigger("change"); }); jQuery.validator.addMethod("telephoneFR", function(value, element) { return this.optional(element) || /^(01|02|03|04|05|06|07|08|09)[0-9]{8}$/.test(value); }, 'Veuillez fournir un numéro de téléphone valide.'); $("input[name='p_1_fonction']").click(function(e) { if($(this).val() == 'Autre') { $("#toggle_p_1_fonction-Autre").slideDown(); } else { $("#toggle_p_1_fonction-Autre").slideUp(); $("#toggle_p_1_fonction-Autre input").prop('checked',false); $("#toggle_p_1_fonction-Autre input[type=text]").val(''); $("#toggle_p_1_fonction-Autre input[type=number]").val(''); $("#toggle_p_1_fonction-Autre input[type=date]").val(''); $("#toggle_p_1_fonction-Autre input[type=email]").val(''); $("#toggle_p_1_fonction-Autre select").val(''); } }); $("input[name='p_2_fonction']").click(function(e) { if($(this).val() == 'Autre') { $("#toggle_p_2_fonction-Autre").slideDown(); } else { $("#toggle_p_2_fonction-Autre").slideUp(); $("#toggle_p_2_fonction-Autre input").prop('checked',false); $("#toggle_p_2_fonction-Autre input[type=text]").val(''); $("#toggle_p_2_fonction-Autre input[type=number]").val(''); $("#toggle_p_2_fonction-Autre input[type=date]").val(''); $("#toggle_p_2_fonction-Autre input[type=email]").val(''); $("#toggle_p_2_fonction-Autre select").val(''); } }); $("input[name='p_3_fonction']").click(function(e) { if($(this).val() == 'Autre') { $("#toggle_p_3_fonction-Autre").slideDown(); } else { $("#toggle_p_3_fonction-Autre").slideUp(); $("#toggle_p_3_fonction-Autre input").prop('checked',false); $("#toggle_p_3_fonction-Autre input[type=text]").val(''); $("#toggle_p_3_fonction-Autre input[type=number]").val(''); $("#toggle_p_3_fonction-Autre input[type=date]").val(''); $("#toggle_p_3_fonction-Autre input[type=email]").val(''); $("#toggle_p_3_fonction-Autre select").val(''); } }); $("input[name='p_4_fonction']").click(function(e) { if($(this).val() == 'Autre') { $("#toggle_p_4_fonction-Autre").slideDown(); } else { $("#toggle_p_4_fonction-Autre").slideUp(); $("#toggle_p_4_fonction-Autre input").prop('checked',false); $("#toggle_p_4_fonction-Autre input[type=text]").val(''); $("#toggle_p_4_fonction-Autre input[type=number]").val(''); $("#toggle_p_4_fonction-Autre input[type=date]").val(''); $("#toggle_p_4_fonction-Autre input[type=email]").val(''); $("#toggle_p_4_fonction-Autre select").val(''); } }); $("input[name='structure_tarif']").click(function(e) { if($(this).val() == 'exposant') { $("#toggle_structure_tarif-exposant").slideDown(); } else { $("#toggle_structure_tarif-exposant").slideUp(); $("#toggle_structure_tarif-exposant input").prop('checked',false); $("#toggle_structure_tarif-exposant input[type=text]").val(''); $("#toggle_structure_tarif-exposant input[type=number]").val(''); $("#toggle_structure_tarif-exposant input[type=date]").val(''); $("#toggle_structure_tarif-exposant input[type=email]").val(''); $("#toggle_structure_tarif-exposant select").val(''); } }); $("input[name='p_1_t3']").click(function(e) { if($(this).val() == 'oui') { $("#toggle_p_1_t3-oui").slideDown(); } else { $("#toggle_p_1_t3-oui").slideUp(); $("#toggle_p_1_t3-oui input").prop('checked',false); $("#toggle_p_1_t3-oui input[type=text]").val(''); $("#toggle_p_1_t3-oui input[type=number]").val(''); $("#toggle_p_1_t3-oui input[type=date]").val(''); $("#toggle_p_1_t3-oui input[type=email]").val(''); $("#toggle_p_1_t3-oui select").val(''); } }); $("input[name='p_2_t3']").click(function(e) { if($(this).val() == 'oui') { $("#toggle_p_2_t3-oui").slideDown(); } else { $("#toggle_p_2_t3-oui").slideUp(); $("#toggle_p_2_t3-oui input").prop('checked',false); $("#toggle_p_2_t3-oui input[type=text]").val(''); $("#toggle_p_2_t3-oui input[type=number]").val(''); $("#toggle_p_2_t3-oui input[type=date]").val(''); $("#toggle_p_2_t3-oui input[type=email]").val(''); $("#toggle_p_2_t3-oui select").val(''); } }); $("input[name='p_3_t3']").click(function(e) { if($(this).val() == 'oui') { $("#toggle_p_3_t3-oui").slideDown(); } else { $("#toggle_p_3_t3-oui").slideUp(); $("#toggle_p_3_t3-oui input").prop('checked',false); $("#toggle_p_3_t3-oui input[type=text]").val(''); $("#toggle_p_3_t3-oui input[type=number]").val(''); $("#toggle_p_3_t3-oui input[type=date]").val(''); $("#toggle_p_3_t3-oui input[type=email]").val(''); $("#toggle_p_3_t3-oui select").val(''); } }); $("input[name='p_4_t3']").click(function(e) { if($(this).val() == 'oui') { $("#toggle_p_4_t3-oui").slideDown(); } else { $("#toggle_p_4_t3-oui").slideUp(); $("#toggle_p_4_t3-oui input").prop('checked',false); $("#toggle_p_4_t3-oui input[type=text]").val(''); $("#toggle_p_4_t3-oui input[type=number]").val(''); $("#toggle_p_4_t3-oui input[type=date]").val(''); $("#toggle_p_4_t3-oui input[type=email]").val(''); $("#toggle_p_4_t3-oui select").val(''); } }); $("input[name='p_1_t5']").click(function(e) { if($(this).val() == 'oui') { $("#toggle_p_1_t5-oui").slideDown(); } else { $("#toggle_p_1_t5-oui").slideUp(); $("#toggle_p_1_t5-oui input").prop('checked',false); $("#toggle_p_1_t5-oui input[type=text]").val(''); $("#toggle_p_1_t5-oui input[type=number]").val(''); $("#toggle_p_1_t5-oui input[type=date]").val(''); $("#toggle_p_1_t5-oui input[type=email]").val(''); $("#toggle_p_1_t5-oui select").val(''); } }); $("input[name='p_2_t5']").click(function(e) { if($(this).val() == 'oui') { $("#toggle_p_2_t5-oui").slideDown(); } else { $("#toggle_p_2_t5-oui").slideUp(); $("#toggle_p_2_t5-oui input").prop('checked',false); $("#toggle_p_2_t5-oui input[type=text]").val(''); $("#toggle_p_2_t5-oui input[type=number]").val(''); $("#toggle_p_2_t5-oui input[type=date]").val(''); $("#toggle_p_2_t5-oui input[type=email]").val(''); $("#toggle_p_2_t5-oui select").val(''); } }); $("input[name='p_3_t5']").click(function(e) { if($(this).val() == 'oui') { $("#toggle_p_3_t5-oui").slideDown(); } else { $("#toggle_p_3_t5-oui").slideUp(); $("#toggle_p_3_t5-oui input").prop('checked',false); $("#toggle_p_3_t5-oui input[type=text]").val(''); $("#toggle_p_3_t5-oui input[type=number]").val(''); $("#toggle_p_3_t5-oui input[type=date]").val(''); $("#toggle_p_3_t5-oui input[type=email]").val(''); $("#toggle_p_3_t5-oui select").val(''); } }); $("input[name='p_4_t5']").click(function(e) { if($(this).val() == 'oui') { $("#toggle_p_4_t5-oui").slideDown(); } else { $("#toggle_p_4_t5-oui").slideUp(); $("#toggle_p_4_t5-oui input").prop('checked',false); $("#toggle_p_4_t5-oui input[type=text]").val(''); $("#toggle_p_4_t5-oui input[type=number]").val(''); $("#toggle_p_4_t5-oui input[type=date]").val(''); $("#toggle_p_4_t5-oui input[type=email]").val(''); $("#toggle_p_4_t5-oui select").val(''); } }); $("#form_jp").validate({ submitHandler: function(form) { calculMontantTotal(); $.ajax({ type: "POST", url: "https://assets.unml.info/php/json.json?snippet=journees&action=journee_save&annee=2019", async: false, data: $("#form_jp").serialize(), dataType : 'json', success: function(d){ $("#btn-submit").attr('disabled', 'disabled'); $("#btn-submit").prepend(' '); //console.log(d); document.location=$("#form_jp").attr('action')+"?c="+d.journee_code; } }); }, rules: { organisme_cp: { required: true, postalFR: true }, responsable_email: { required: true, email: true }, responsable_email_confirmation: { equalTo: "#responsable_email" }, responsable_telephone: { required: true, telephoneFR: true }, participant_email_1: { required: true, email: true }, participant_email_confirmation_1: { equalTo: "#participant_email_1" }, participant_telephone_1: { required: true, telephoneFR: true }, participant_email_2: { required: true, email: true }, participant_email_confirmation_2: { required: true, email: true, equalTo: "#participant_email_2" }, participant_telephone_2: { required: true, telephoneFR: true }, participant_email_3: { required: true, email: true }, participant_email_confirmation_3: { required: true, email: true, equalTo: "#participant_email_3" }, participant_telephone_3: { required: true, telephoneFR: true }, participant_email_4: { required: true, email: true }, participant_email_confirmation_4: { required: true, email: true, equalTo: "#participant_email_4" }, participant_telephone_4: { required: true, telephoneFR: true }, participant_email_5: { required: true, email: true }, participant_email_confirmation_5: { required: true, email: true, equalTo: "#participant_email_5" }, participant_telephone_5: { required: true, telephoneFR: true } }, messages: { responsable_email_confirmation: "Veuillez renseigner la même adresse électronique.", participant_email_confirmation_1: "Veuillez renseigner la même adresse électronique.", participant_email_confirmation_2: "Veuillez renseigner la même adresse électronique.", participant_email_confirmation_3: "Veuillez renseigner la même adresse électronique.", participant_email_confirmation_4: "Veuillez renseigner la même adresse électronique.", participant_email_confirmation_5: "Veuillez renseigner la même adresse électronique." } }); }); function calculMontantTotal() { montantTotal = 0; tarif = 350; montantTotal = tarif * $(".participant:visible", "#form_jp").length; $("#montantTotal").val(montantTotal); return montantTotal; }