From b2b739becfd9442c8e9b52278926e4bc209d60e6 Mon Sep 17 00:00:00 2001 From: Neda Taherifar Date: Tue, 30 Jul 2024 11:21:40 +0800 Subject: [PATCH] Fix issue with elevation input field: Ensure consistent behavior across browsers #262 --- ckan/src/shared/public/base/js/map-module.js | 19 +++++++++++++++++++ .../form_snippets/spatial_fields.html | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ckan/src/shared/public/base/js/map-module.js b/ckan/src/shared/public/base/js/map-module.js index 476300d8f..2a4144f58 100644 --- a/ckan/src/shared/public/base/js/map-module.js +++ b/ckan/src/shared/public/base/js/map-module.js @@ -8,6 +8,9 @@ ckan.module('map-module', function ($, _) { this.singleMode = this.options.singleMode; this.el.ready($.proxy(this.setupMap, this)); + + this.setupElevationField(); + }, setupMap: function () { @@ -547,6 +550,22 @@ ckan.module('map-module', function ($, _) { }, + setupElevationField: function () { + document.getElementById('field-elevation').addEventListener('input', function (event) { + const inputField = event.target; + const value = inputField.value; + const validValue = value.replace(/[^0-9.]/g, ''); + const parts = validValue.split('.'); + if (parts.length > 2) { + inputField.value = parts[0] + '.' + parts.slice(1).join(''); + } else { + inputField.value = validValue; + } + if (parseFloat(inputField.value) < 0) { + inputField.value = ''; + } + }); + }, }; }); diff --git a/ckan/src/shared/templates/scheming/form_snippets/spatial_fields.html b/ckan/src/shared/templates/scheming/form_snippets/spatial_fields.html index b4612b114..f381ef9ed 100644 --- a/ckan/src/shared/templates/scheming/form_snippets/spatial_fields.html +++ b/ckan/src/shared/templates/scheming/form_snippets/spatial_fields.html @@ -57,7 +57,8 @@
- + + {% if errors['elevation'] %} {% for error in errors['elevation'] %} {{ error }}