fix(public): réinitialisation dynamique et nettoyage serveur des champs du formulaire selon le type de demande
This commit is contained in:
+14
@@ -135,6 +135,20 @@ public class PublicInscriptionController {
|
|||||||
return "redirect:/inscription-public/demarrer";
|
return "redirect:/inscription-public/demarrer";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nettoyage défensif des champs non applicables
|
||||||
|
if ("RENOUVELLEMENT".equals(preInscription.getTypeDemande())) {
|
||||||
|
preInscription.setAncienClub(null);
|
||||||
|
preInscription.setRaisonChangementClub(null);
|
||||||
|
preInscription.setAncienneCategorie(null);
|
||||||
|
preInscription.setCommentConnuClub(null);
|
||||||
|
}
|
||||||
|
if (preInscription.getDateNaissance() != null) {
|
||||||
|
int age = java.time.Period.between(preInscription.getDateNaissance(), java.time.LocalDate.now()).getYears();
|
||||||
|
if (age >= 18) {
|
||||||
|
preInscription.setRepresentantLegal(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Sauvegarde de la pré-inscription
|
// Sauvegarde de la pré-inscription
|
||||||
preInscription.setSaison(activeSaison);
|
preInscription.setSaison(activeSaison);
|
||||||
preInscription.setStatutTraite(false);
|
preInscription.setStatutTraite(false);
|
||||||
|
|||||||
@@ -206,6 +206,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
const form = document.querySelector('form');
|
const form = document.querySelector('form');
|
||||||
|
|
||||||
form.addEventListener('submit', function(event) {
|
form.addEventListener('submit', function(event) {
|
||||||
if (!form.checkValidity()) {
|
if (!form.checkValidity()) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -230,32 +231,71 @@
|
|||||||
|
|
||||||
const typeDemandeRadios = document.querySelectorAll('input[name="typeDemande"]');
|
const typeDemandeRadios = document.querySelectorAll('input[name="typeDemande"]');
|
||||||
const nouvelleLicenceBlock = document.getElementById('nouvelleLicenceBlock');
|
const nouvelleLicenceBlock = document.getElementById('nouvelleLicenceBlock');
|
||||||
|
|
||||||
typeDemandeRadios.forEach(radio => {
|
|
||||||
radio.addEventListener('change', function() {
|
|
||||||
if (this.value === 'NOUVELLE') {
|
|
||||||
nouvelleLicenceBlock.classList.remove('hidden');
|
|
||||||
} else {
|
|
||||||
nouvelleLicenceBlock.classList.add('hidden');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Trigger on load if already checked (e.g. going back or validation error)
|
|
||||||
const checkedRadio = document.querySelector('input[name="typeDemande"]:checked');
|
|
||||||
if (checkedRadio && checkedRadio.value === 'NOUVELLE') {
|
|
||||||
nouvelleLicenceBlock.classList.remove('hidden');
|
|
||||||
}
|
|
||||||
|
|
||||||
const ancienClubInput = document.getElementById('ancienClub');
|
const ancienClubInput = document.getElementById('ancienClub');
|
||||||
const ancienneCategorieBlock = document.getElementById('ancienneCategorieBlock');
|
const ancienneCategorieBlock = document.getElementById('ancienneCategorieBlock');
|
||||||
const ancienneCategorieSelect = document.getElementById('ancienneCategorie');
|
const ancienneCategorieSelect = document.getElementById('ancienneCategorie');
|
||||||
const raisonChangementClubBlock = document.getElementById('raisonChangementClubBlock');
|
const raisonChangementClubBlock = document.getElementById('raisonChangementClubBlock');
|
||||||
const raisonChangementClubInput = document.getElementById('raisonChangementClub');
|
const raisonChangementClubInput = document.getElementById('raisonChangementClub');
|
||||||
|
const commentConnuInput = document.querySelector('input[name="commentConnuClub"]');
|
||||||
|
|
||||||
|
function updateTypeDemandeState(typeValue) {
|
||||||
|
if (typeValue === 'NOUVELLE') {
|
||||||
|
nouvelleLicenceBlock.classList.remove('hidden');
|
||||||
|
// Synchroniser l'état de l'ancien club s'il contient du texte
|
||||||
|
if (ancienClubInput && ancienClubInput.value.trim().length > 0) {
|
||||||
|
ancienneCategorieBlock.classList.remove('hidden');
|
||||||
|
ancienneCategorieSelect.required = true;
|
||||||
|
raisonChangementClubBlock.classList.remove('hidden');
|
||||||
|
raisonChangementClubInput.required = true;
|
||||||
|
} else {
|
||||||
|
ancienneCategorieBlock.classList.add('hidden');
|
||||||
|
ancienneCategorieSelect.required = false;
|
||||||
|
raisonChangementClubBlock.classList.add('hidden');
|
||||||
|
raisonChangementClubInput.required = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// RENOUVELLEMENT
|
||||||
|
nouvelleLicenceBlock.classList.add('hidden');
|
||||||
|
|
||||||
|
// Réinitialisation complète des champs spécifiques aux nouvelles demandes
|
||||||
|
if (ancienClubInput) ancienClubInput.value = '';
|
||||||
|
if (raisonChangementClubInput) {
|
||||||
|
raisonChangementClubInput.value = '';
|
||||||
|
raisonChangementClubInput.required = false;
|
||||||
|
}
|
||||||
|
if (ancienneCategorieSelect) {
|
||||||
|
ancienneCategorieSelect.value = 'NA';
|
||||||
|
ancienneCategorieSelect.required = false;
|
||||||
|
}
|
||||||
|
if (commentConnuInput) commentConnuInput.value = '';
|
||||||
|
|
||||||
|
if (ancienneCategorieBlock) ancienneCategorieBlock.classList.add('hidden');
|
||||||
|
if (raisonChangementClubBlock) raisonChangementClubBlock.classList.add('hidden');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si le formulaire redevient valide, masquer le message d'erreur
|
||||||
|
const errorMsg = document.getElementById('form-error-msg');
|
||||||
|
if (errorMsg && form.checkValidity()) {
|
||||||
|
errorMsg.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typeDemandeRadios.forEach(radio => {
|
||||||
|
radio.addEventListener('change', function() {
|
||||||
|
updateTypeDemandeState(this.value);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Exécution initiale au chargement si un type est déjà coché
|
||||||
|
const checkedRadio = document.querySelector('input[name="typeDemande"]:checked');
|
||||||
|
if (checkedRadio) {
|
||||||
|
updateTypeDemandeState(checkedRadio.value);
|
||||||
|
}
|
||||||
|
|
||||||
if (ancienClubInput) {
|
if (ancienClubInput) {
|
||||||
ancienClubInput.addEventListener('input', function() {
|
ancienClubInput.addEventListener('input', function() {
|
||||||
if (this.value.trim().length > 0) {
|
const isNouvelle = document.querySelector('input[name="typeDemande"]:checked')?.value === 'NOUVELLE';
|
||||||
|
if (isNouvelle && this.value.trim().length > 0) {
|
||||||
ancienneCategorieBlock.classList.remove('hidden');
|
ancienneCategorieBlock.classList.remove('hidden');
|
||||||
ancienneCategorieSelect.required = true;
|
ancienneCategorieSelect.required = true;
|
||||||
raisonChangementClubBlock.classList.remove('hidden');
|
raisonChangementClubBlock.classList.remove('hidden');
|
||||||
@@ -267,16 +307,11 @@
|
|||||||
raisonChangementClubInput.required = false;
|
raisonChangementClubInput.required = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Initial check
|
|
||||||
if (ancienClubInput.value.trim().length > 0) {
|
|
||||||
ancienneCategorieBlock.classList.remove('hidden');
|
|
||||||
ancienneCategorieSelect.required = true;
|
|
||||||
raisonChangementClubBlock.classList.remove('hidden');
|
|
||||||
raisonChangementClubInput.required = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('dateNaissance').addEventListener('change', function() {
|
const dateNaissanceInput = document.getElementById('dateNaissance');
|
||||||
|
if (dateNaissanceInput) {
|
||||||
|
dateNaissanceInput.addEventListener('change', function() {
|
||||||
const dateInput = this.value;
|
const dateInput = this.value;
|
||||||
const repBlock = document.getElementById('representantBlock');
|
const repBlock = document.getElementById('representantBlock');
|
||||||
const repInput = document.getElementById('representantLegal');
|
const repInput = document.getElementById('representantLegal');
|
||||||
@@ -293,9 +328,15 @@
|
|||||||
} else {
|
} else {
|
||||||
repBlock.classList.add('hidden');
|
repBlock.classList.add('hidden');
|
||||||
repInput.required = false;
|
repInput.required = false;
|
||||||
|
repInput.value = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// Vérification initiale si la date est pré-remplie
|
||||||
|
if (dateNaissanceInput.value) {
|
||||||
|
dateNaissanceInput.dispatchEvent(new Event('change'));
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user