Skip to content
Snippets Groups Projects
Commit f5072efe authored by Lene Wasskog's avatar Lene Wasskog
Browse files

fix: Weatherstation validation, form logic

parent bace2acb
Branches
No related tags found
No related merge requests found
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
</label> </label>
<div id="input-weatherstation" style="display: none;"> <div id="input-weatherstation" style="display: none;">
<select name="weatherStationId" id="weatherStationId" class="form-control" onblur="validateField(this);"></select> <select name="weatherStationId" id="weatherStationId" class="form-control" onblur="validateField(this);"></select>
<button type="button" class="btn btn-primary" onclick.prevent="openPoiMap()"><i class="fa fa-map-marker fa-lg"></i> Velg i kart</button> <button type="button" class="btn btn-primary" onclick="openPoiMap()"><i class="fa fa-map-marker fa-lg"></i> Velg i kart</button>
</div> </div>
<div id="poi-map" class="map-modal"></div> <div id="poi-map" class="map-modal"></div>
</div> </div>
...@@ -197,14 +197,14 @@ ...@@ -197,14 +197,14 @@
const inputLatitudeElement = document.getElementById("latitude"); const inputLatitudeElement = document.getElementById("latitude");
const inputLongitudeElement = document.getElementById("longitude"); const inputLongitudeElement = document.getElementById("longitude");
const selectPoiElement = document.getElementById("weatherStationId"); const selectWeatherstationElement = document.getElementById("weatherStationId");
let poiIdList = [] let poiIdList = []
let selectedPoint = null; let selectedPoint = null;
let selectedFeature = undefined; let selectedFeature = undefined;
function getSelectedPoiId() { function getSelectedPoiId() {
const value = selectPoiElement.value; const value = selectWeatherstationElement.value;
const parsedValue = parseInt(value, 10); const parsedValue = parseInt(value, 10);
return (!isNaN(parsedValue) && parsedValue > 0) ? parsedValue : undefined; return (!isNaN(parsedValue) && parsedValue > 0) ? parsedValue : undefined;
} }
...@@ -222,9 +222,9 @@ ...@@ -222,9 +222,9 @@
function selectPoi(poiData) { function selectPoi(poiData) {
const selectedId = poiData ? poiData.pointOfInterestId : undefined; const selectedId = poiData ? poiData.pointOfInterestId : undefined;
if (selectedId) { if (selectedId) {
const optionIndex = Array.from(selectPoiElement.options).findIndex(option => option.value == selectedId); const optionIndex = Array.from(selectWeatherstationElement.options).findIndex(option => option.value == selectedId);
if (optionIndex !== -1) { if (optionIndex !== -1) {
selectPoiElement.selectedIndex = optionIndex; selectWeatherstationElement.selectedIndex = optionIndex;
} else { } else {
console.error(`No matching option found for poi.id=${selectedId}`); console.error(`No matching option found for poi.id=${selectedId}`);
} }
...@@ -286,13 +286,18 @@ ...@@ -286,13 +286,18 @@
window.displayWeatherstationInput = () => { window.displayWeatherstationInput = () => {
document.getElementById("weatherstation").checked = true;
document.getElementById('input-weatherstation').style.display="block"; document.getElementById('input-weatherstation').style.display="block";
document.getElementById('input-coordinates').style.display="none"; document.getElementById('input-coordinates').style.display="none";
inputLatitudeElement.value = ""
inputLongitudeElement.value = ""
} }
window.displayCoordinatesInput = (id) => { window.displayCoordinatesInput = (id) => {
document.getElementById("coordinates").checked = true;
document.getElementById('input-weatherstation').style.display="none"; document.getElementById('input-weatherstation').style.display="none";
document.getElementById('input-coordinates').style.display="block"; document.getElementById('input-coordinates').style.display="block";
selectWeatherstationElement.selectedIndex = 0;
} }
window.validateFormExtra = () => { window.validateFormExtra = () => {
...@@ -307,8 +312,10 @@ ...@@ -307,8 +312,10 @@
return false; return false;
} }
} }
if (selectedWeatherdataType === "weatherstation" && theForm["weatherStationId"].value === -1) { if (selectedWeatherdataType === "weatherstation") {
alert("Mangler værstasjon") if(theForm["weatherStationId"].options[theForm["weatherStationId"].selectedIndex].value == "-1") {
alert("Mangler værstasjon")
}
} }
// Observation: Either no fields or all fields must be set // Observation: Either no fields or all fields must be set
...@@ -531,6 +538,7 @@ ...@@ -531,6 +538,7 @@
initPreparations(); initPreparations();
// Init form validation // Init form validation
loadFormDefinition("{{ form_id }}","/static/cerealblotchmodels/formdefinitions/"); loadFormDefinition("{{ form_id }}","/static/cerealblotchmodels/formdefinitions/");
displayCoordinatesInput();
}); });
</script> </script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment