Fixed mandatory radius field if geo-restricted is checked

nodejs
Aravind142857 2 years ago
parent 2747fd5b76
commit cd0b04b488

@ -15,8 +15,21 @@
<span role="alert" id="error" aria-hidden="true">Invalid entry</span> <span role="alert" id="error" aria-hidden="true">Invalid entry</span>
<br><br>
<label for="restricted">Geo-restricted?: </label><input type="checkbox" name="restricted" id="restricted">
<br><br>
<label for="radiusSelect" hidden="hidden" id="radiusLabel">Radius: </label><span id="mandatory-radius"class="mandatory" hidden="hidden">*</span>
<select name="radiusSelect" id="radiusSelect" hidden="hidden" required>
<option value="" selected disabled hidden>Choose a radius for your geo link</option>
<option value="5">5 mi</option>
<option value="10">10 mi</option>
<option value="15">15 mi</option>
<option value="20">20 mi</option>
</select>
<br><br> <br><br>
<input type="submit" id="button" value="Zip It!"> <input type="submit" id="button" value="Zip It!">
<input type="hidden" name="latitude" id="latitude">
<input type="hidden" name="longitude" id="longitude">
</form> </form>
<hr> <hr>
<div> <div>

@ -1,5 +1,42 @@
// const submit = document.getElementById("button"); // const submit = document.getElementById("button");
mycheckbox = document.getElementById("restricted");
mycheckbox.addEventListener('change',checkboxCallback);
function checkboxCallback(event) {
const radiusLabel = document.getElementById("radiusLabel");
const radiusSelect = document.getElementById("radiusSelect");
const mandatoryRadius = document.getElementById("mandatory-radius");
if (event.currentTarget.checked) {
radiusLabel.hidden = false;
mandatoryRadius.hidden = false;
radiusSelect.hidden = false;
//radiusSelect.required = true;
getLocation();
} else {
radiusLabel.hidden = true;
mandatoryRadius.hidden = true;
radiusSelect.hidden = true;
//radiusSelect.required = false;
}
}
function getLocation() {
console.log("GeoLocation");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
console.log("Your browser does not support geolocation.");
}
}
function showPosition(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
document.getElementById("latitude").value = position.coords.latitude;
document.getElementById("longitude").value = position.coords.longitude;
console.log("done");
}
// submit.addEventListener('click', validate); // submit.addEventListener('click', validate);
function validate() { function validate() {

@ -68,7 +68,7 @@ function filter(path) {
} }
return path; return path;
} else { } else {
console.log("failed check"); console.log("failed check. path is " + path);
return null; return null;
} }

Loading…
Cancel
Save