Skip to content

Commit

Permalink
Fix issue with elevation input field: Ensure consistent behavior acro…
Browse files Browse the repository at this point in the history
…ss browsers #262
  • Loading branch information
NTaherifar committed Jul 30, 2024
1 parent 186e907 commit b2b739b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions ckan/src/shared/public/base/js/map-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 = '';
}
});
},
};
});

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
</div>
<div class="form-group" id="elevation_container">
<label for="field-elevation">Elevation</label>
<input type="number" class="form-control" id="field-elevation" name="elevation" value="{{data['elevation']}}" >
<input class="form-control" id="field-elevation" name="elevation" value="{{ data['elevation'] }}" step="any" min="0">

{% if errors['elevation'] %}
{% for error in errors['elevation'] %}
<span class="error-block">{{ error }}</span>
Expand Down

0 comments on commit b2b739b

Please sign in to comment.