Skip to content

Commit

Permalink
fix(isochrone): wrong rules for form validation
Browse files Browse the repository at this point in the history
  • Loading branch information
azarz committed Nov 27, 2024
1 parent 8956278 commit e6290de
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
22 changes: 21 additions & 1 deletion src/js/isochrone/isochrone-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,22 @@ let IsochroneDOM = {
});
}
e.target.value = !!e.target.value && parseFloat(e.target.value) < 0 ? 0 : parseFloat(e.target.value) > limit ? limit : e.target.value;
if (e.target.value > 0 && self.dom.location.dataset.coordinates) {
};
};

const checkInputValidity = (checkBox) => {
return function(e) {
if (e.target.value > 0 && checkBox.checked && self.dom.location.dataset.coordinates) {
self.dom.isochroneCompute.classList.remove("disabled");
} else {
self.dom.isochroneCompute.classList.add("disabled");
}
};
};

const checkCheckboxValidity = (input) => {
return function(e) {
if (input.value > 0 && e.target.checked && self.dom.location.dataset.coordinates) {
self.dom.isochroneCompute.classList.remove("disabled");
} else {
self.dom.isochroneCompute.classList.add("disabled");
Expand All @@ -200,6 +215,11 @@ let IsochroneDOM = {

this.dom.durationValueMinutes.addEventListener("input", limitInputValue(60));
this.dom.distanceValue.addEventListener("input", limitInputValue(50));
this.dom.durationValueMinutes.addEventListener("input", checkInputValidity(this.dom.modeDuration));
this.dom.distanceValue.addEventListener("input", checkInputValidity(this.dom.modeDistance));

this.dom.modeDistance.addEventListener("change", checkCheckboxValidity(this.dom.distanceValue));
this.dom.modeDuration.addEventListener("change", checkCheckboxValidity(this.dom.durationValueMinutes));

this.dom.showOutPoisChk.addEventListener("change", (e) => {
if (e.target.checked) {
Expand Down
17 changes: 15 additions & 2 deletions src/js/isochrone/isochrone.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,21 @@ class Isochrone {
this.map.moveLayer(this.configuration.source, this.configuration.source + "line");
}

/**
* nettoyage du formularie
* @public
*/
clearForm() {
this.dom.location.value = "";
this.dom.location.dataset.coordinates = "";
this.dom.distanceValue.value = "";
this.dom.durationValueMinutes.value = "";
this.dom.clearLocation.classList.add("d-none");
}

/**
* nettoyage du tracé
* @public
* @todo supprimer la couche POI isochrone
*/
clear() {
// stopper le fetch en cours sur le service
Expand Down Expand Up @@ -520,7 +531,9 @@ class Isochrone {
target.dataset.coordinates = "[" + e.detail.coordinates.lon + "," + e.detail.coordinates.lat + "]";
target.value = e.detail.text;
self.dom.clearLocation.classList.remove("d-none");
if (parseFloat(self.dom.distanceValue.value) > 0 || parseFloat(self.dom.durationValueMinutes.value) > 0) {
if (self.dom.modeDistance.checked && parseFloat(self.dom.distanceValue.value) > 0 ||
self.dom.modeDuration.checked && parseFloat(self.dom.durationValueMinutes.value) > 0
) {
self.dom.isochroneCompute.classList.remove("disabled");
}
// on supprime les écouteurs
Expand Down
1 change: 1 addition & 0 deletions src/js/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ class MenuNavigation {
DOM.$fullScreenBtn.classList.remove("highest");
DOM.$backTopLeftBtn.classList.add("d-none");
Globals.isochrone.clear();
Globals.isochrone.clearForm();
Globals.interactivityIndicator.enable();
break;
case "search":
Expand Down

0 comments on commit e6290de

Please sign in to comment.