fix selection commune/voie
This commit is contained in:
parent
7672a52239
commit
3fe2a4af9c
1 changed files with 21 additions and 15 deletions
|
@ -35,7 +35,7 @@
|
||||||
<form method="post" action="/test/pto">
|
<form method="post" action="/test/pto">
|
||||||
<div class="form-group" id="ptoForm">
|
<div class="form-group" id="ptoForm">
|
||||||
<label class="form-label" for="pto-number">Numéro PTO</label>
|
<label class="form-label" for="pto-number">Numéro PTO</label>
|
||||||
<input required type="text" class="form-control" name="pto" id="pto-number" aria-describedby="ptoHelp"
|
<input autofocus required type="text" class="form-control" name="pto" id="pto-number" aria-describedby="ptoHelp"
|
||||||
placeholder="OOOO-XXXX-XXXX" oninvalid="this.setCustomValidity('Veuillez renseigner le PTO')"
|
placeholder="OOOO-XXXX-XXXX" oninvalid="this.setCustomValidity('Veuillez renseigner le PTO')"
|
||||||
oninput="setCustomValidity('')">
|
oninput="setCustomValidity('')">
|
||||||
|
|
||||||
|
@ -139,15 +139,21 @@
|
||||||
fetch(api, { signalCommunes })
|
fetch(api, { signalCommunes })
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
valueMatch=false;
|
||||||
if (JSON.stringify(data) !== JSON.stringify(communes)) {
|
if (JSON.stringify(data) !== JSON.stringify(communes)) {
|
||||||
$("#communes").empty();
|
$("#communes").empty();
|
||||||
communes = data
|
communes = data
|
||||||
communes.forEach(commune => {
|
communes.forEach(commune => {
|
||||||
|
value=commune.codeZip + ' ' + commune.nom
|
||||||
$("#communes").append("<option codeInsee=" + commune.codeInsee + " value='" +
|
$("#communes").append("<option codeInsee=" + commune.codeInsee + " value='" +
|
||||||
commune.codeZip + ' ' + commune.nom + "'></option>");
|
value + "'></option>");
|
||||||
|
if (value === search) {
|
||||||
|
valueMatch=true;
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (communes.length == 1) {
|
if (communes.length == 1 || valueMatch) {
|
||||||
codeInsee = communes[0].codeInsee;
|
codeInsee = communes[0].codeInsee;
|
||||||
$('#voieForm').collapse('show');
|
$('#voieForm').collapse('show');
|
||||||
} else {
|
} else {
|
||||||
|
@ -156,10 +162,6 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|
||||||
if (err.name === "AbortError") {
|
|
||||||
console.log("DEBUG: updateCommunes aborted !")
|
|
||||||
}
|
|
||||||
console.error("Error fetching communes:", err)
|
console.error("Error fetching communes:", err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -173,30 +175,29 @@
|
||||||
fetch(api, { signalVoies })
|
fetch(api, { signalVoies })
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
valueMatch=false;
|
||||||
if (JSON.stringify(data) !== JSON.stringify(voies)) {
|
if (JSON.stringify(data) !== JSON.stringify(voies)) {
|
||||||
$("#voies").empty();
|
$("#voies").empty();
|
||||||
voies = Object.entries(data);
|
voies = Object.entries(data);
|
||||||
console.log(voies)
|
|
||||||
let voie;
|
let voie;
|
||||||
for (i in voies) {
|
for (i in voies) {
|
||||||
voie = voies[i]
|
voie = voies[i]
|
||||||
$("#voies").append("<option id=" + voie[1] + " value='" +
|
$("#voies").append("<option id=" + voie[1] + " value='" +
|
||||||
voie[0] + "'></option>");
|
voie[0] + "'></option>");
|
||||||
|
if (voie[0] === search) {
|
||||||
|
valueMatch=true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
console.log(voies)
|
if (voies.length == 1 || valueMatch) {
|
||||||
if (voies.length == 1) {
|
|
||||||
$('#btnTestAdresse').collapse('show');
|
$('#btnTestAdresse').collapse('show');
|
||||||
voie = voies[0]
|
voie = voies[0]
|
||||||
|
$('#btnTestAdresse').focus();
|
||||||
} else {
|
} else {
|
||||||
$('#btnTestAdresse').collapse('hide');
|
$('#btnTestAdresse').collapse('hide');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|
||||||
if (err.name === "AbortError") {
|
|
||||||
console.log("DEBUG: updateCommunes aborted !")
|
|
||||||
}
|
|
||||||
console.error("Error fetching communes:", err)
|
console.error("Error fetching communes:", err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -204,10 +205,16 @@
|
||||||
$('#communeInput').trigger('input')
|
$('#communeInput').trigger('input')
|
||||||
$('#communeInput').trigger('keyup')
|
$('#communeInput').trigger('keyup')
|
||||||
});
|
});
|
||||||
|
$('#methodAddress').on('shown.bs.collapse', function () {
|
||||||
|
$('#communeInput').focus();
|
||||||
|
});
|
||||||
$('#voieForm').on('show.bs.collapse', function () {
|
$('#voieForm').on('show.bs.collapse', function () {
|
||||||
$('#voieInput').trigger('input')
|
$('#voieInput').trigger('input')
|
||||||
$('#voieInput').trigger('keyup')
|
$('#voieInput').trigger('keyup')
|
||||||
});
|
});
|
||||||
|
$('#voieForm').on('shown.bs.collapse', function () {
|
||||||
|
$('#numeroVoieInput').focus();
|
||||||
|
});
|
||||||
|
|
||||||
$('#communeInput').on('keyup', function () {
|
$('#communeInput').on('keyup', function () {
|
||||||
controllerCommunes.abort();
|
controllerCommunes.abort();
|
||||||
|
@ -232,7 +239,6 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#formAddressTest').submit(function(eventObj) {
|
$('#formAddressTest').submit(function(eventObj) {
|
||||||
console.log("SUBMIT",$('#formAddressTest'))
|
|
||||||
$('#formAddressTest').append(`<input type="hidden" class="form-control" name="codeInsee" value="${codeInsee}" />`);
|
$('#formAddressTest').append(`<input type="hidden" class="form-control" name="codeInsee" value="${codeInsee}" />`);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue