From 3fe2a4af9c563626f11f7fbf83ee598d5949308d Mon Sep 17 00:00:00 2001 From: Johan Le Baut Date: Sat, 12 Feb 2022 21:31:23 +0100 Subject: [PATCH] fix selection commune/voie --- templates/landing_form.html | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/templates/landing_form.html b/templates/landing_form.html index b93531f..b12da24 100644 --- a/templates/landing_form.html +++ b/templates/landing_form.html @@ -35,7 +35,7 @@
- @@ -139,15 +139,21 @@ fetch(api, { signalCommunes }) .then(response => response.json()) .then(data => { + valueMatch=false; if (JSON.stringify(data) !== JSON.stringify(communes)) { $("#communes").empty(); communes = data communes.forEach(commune => { + value=commune.codeZip + ' ' + commune.nom $("#communes").append(""); + value + "'>"); + if (value === search) { + valueMatch=true; + } + }); } - if (communes.length == 1) { + if (communes.length == 1 || valueMatch) { codeInsee = communes[0].codeInsee; $('#voieForm').collapse('show'); } else { @@ -156,10 +162,6 @@ } }) .catch(err => { - - if (err.name === "AbortError") { - console.log("DEBUG: updateCommunes aborted !") - } console.error("Error fetching communes:", err) }) } @@ -173,30 +175,29 @@ fetch(api, { signalVoies }) .then(response => response.json()) .then(data => { + valueMatch=false; if (JSON.stringify(data) !== JSON.stringify(voies)) { $("#voies").empty(); voies = Object.entries(data); - console.log(voies) let voie; for (i in voies) { voie = voies[i] $("#voies").append(""); + if (voie[0] === search) { + valueMatch=true; + } } - console.log(voies) - if (voies.length == 1) { + if (voies.length == 1 || valueMatch) { $('#btnTestAdresse').collapse('show'); voie = voies[0] + $('#btnTestAdresse').focus(); } else { $('#btnTestAdresse').collapse('hide'); } } }) .catch(err => { - - if (err.name === "AbortError") { - console.log("DEBUG: updateCommunes aborted !") - } console.error("Error fetching communes:", err) }) } @@ -204,10 +205,16 @@ $('#communeInput').trigger('input') $('#communeInput').trigger('keyup') }); + $('#methodAddress').on('shown.bs.collapse', function () { + $('#communeInput').focus(); + }); $('#voieForm').on('show.bs.collapse', function () { $('#voieInput').trigger('input') $('#voieInput').trigger('keyup') }); + $('#voieForm').on('shown.bs.collapse', function () { + $('#numeroVoieInput').focus(); + }); $('#communeInput').on('keyup', function () { controllerCommunes.abort(); @@ -232,7 +239,6 @@ }); $('#formAddressTest').submit(function(eventObj) { - console.log("SUBMIT",$('#formAddressTest')) $('#formAddressTest').append(``); return true; });