diff --git a/cerealblotchmodels/templates/cerealblotchmodels/barleynetblotchform.html b/cerealblotchmodels/templates/cerealblotchmodels/barleynetblotchform.html index 71e28d651102fee1d0a3438a7a83071d59367dc4..999fcd1a6397c381afffd4f540b90bbfce36172b 100755 --- a/cerealblotchmodels/templates/cerealblotchmodels/barleynetblotchform.html +++ b/cerealblotchmodels/templates/cerealblotchmodels/barleynetblotchform.html @@ -93,7 +93,7 @@ </label> <div id="input-weatherstation" style="display: none;"> <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 id="poi-map" class="map-modal"></div> </div> @@ -197,14 +197,14 @@ const inputLatitudeElement = document.getElementById("latitude"); const inputLongitudeElement = document.getElementById("longitude"); - const selectPoiElement = document.getElementById("weatherStationId"); + const selectWeatherstationElement = document.getElementById("weatherStationId"); let poiIdList = [] let selectedPoint = null; let selectedFeature = undefined; function getSelectedPoiId() { - const value = selectPoiElement.value; + const value = selectWeatherstationElement.value; const parsedValue = parseInt(value, 10); return (!isNaN(parsedValue) && parsedValue > 0) ? parsedValue : undefined; } @@ -222,9 +222,9 @@ function selectPoi(poiData) { const selectedId = poiData ? poiData.pointOfInterestId : undefined; 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) { - selectPoiElement.selectedIndex = optionIndex; + selectWeatherstationElement.selectedIndex = optionIndex; } else { console.error(`No matching option found for poi.id=${selectedId}`); } @@ -286,13 +286,18 @@ window.displayWeatherstationInput = () => { + document.getElementById("weatherstation").checked = true; document.getElementById('input-weatherstation').style.display="block"; document.getElementById('input-coordinates').style.display="none"; + inputLatitudeElement.value = "" + inputLongitudeElement.value = "" } window.displayCoordinatesInput = (id) => { + document.getElementById("coordinates").checked = true; document.getElementById('input-weatherstation').style.display="none"; document.getElementById('input-coordinates').style.display="block"; + selectWeatherstationElement.selectedIndex = 0; } window.validateFormExtra = () => { @@ -307,8 +312,10 @@ return false; } } - if (selectedWeatherdataType === "weatherstation" && theForm["weatherStationId"].value === -1) { - alert("Mangler værstasjon") + if (selectedWeatherdataType === "weatherstation") { + if(theForm["weatherStationId"].options[theForm["weatherStationId"].selectedIndex].value == "-1") { + alert("Mangler værstasjon") + } } // Observation: Either no fields or all fields must be set @@ -531,6 +538,7 @@ initPreparations(); // Init form validation loadFormDefinition("{{ form_id }}","/static/cerealblotchmodels/formdefinitions/"); + displayCoordinatesInput(); }); </script>