Skip to content

Commit

Permalink
Allow entering decimals (#830, PR #868)
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi authored and wvengen committed Dec 14, 2022
1 parent d0110a7 commit ec6d69c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/assets/javascripts/delta_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function data_delta_update(el, direction) {
var delta = $(el).data('delta');
var granularity = $(el).data('granularity');

var val = $(el).val();
var val = $(el).val().replace(',', '.');
var oldval = $.isNumeric(val) ? Number(val) : 0;
var newval = oldval + delta*direction;

Expand All @@ -31,10 +31,11 @@ function data_delta_update(el, direction) {
$('button[data-increment='+id+']').attr('disabled', newval>=max ? 'disabled' : null);

// warn when what was entered is not a number
$(el).toggleClass('error', val!='' && val!='.' && (!$.isNumeric(val) || val < 0));
const erroneousValue = val!='' && val!='.' && (!$.isNumeric(val) || val < 0)
$(el).toggleClass('error', erroneousValue);

// update field, unless the user is typing
if (!$(el).is(':focus')) {
if (!$(el).is(':focus') && !erroneousValue) {
$(el).val(round_float(newval, granularity));
$(el).trigger('changed');
}
Expand Down

0 comments on commit ec6d69c

Please sign in to comment.