Fix decimal render function [SCI-6742] (#4037)

Co-authored-by: Anton <anton@scinote.net>
This commit is contained in:
aignatov-bio 2022-04-20 11:07:37 +02:00 committed by GitHub
parent 4daf01feee
commit 918a11a0b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 12 deletions

View file

@ -1,13 +1,8 @@
/* global SmartAnnotation I18n MyModuleRepositories GLOBAL_CONSTANTS */ /* global SmartAnnotation I18n MyModuleRepositories GLOBAL_CONSTANTS formatDecimalValue */
var MyModuleStockConsumption = (function() { var MyModuleStockConsumption = (function() {
const CONSUMPTION_MODAL = '#consumeRepositoryStockValueModal'; const CONSUMPTION_MODAL = '#consumeRepositoryStockValueModal';
const WARNING_MODAL = '#consumeRepositoryStockValueModalWarning'; const WARNING_MODAL = '#consumeRepositoryStockValueModalWarning';
function formatDecimalValue(value, decimals) {
let regexp = decimals === 0 ? /[^0-9-]/g : /[^0-9.-]/g;
return value.replace(regexp, '').match(new RegExp(`^-?\\d*(\\.\\d{0,${decimals}})?`))[0];
}
function focusStockConsumption() { function focusStockConsumption() {
// focus and move cursor to end of text // focus and move cursor to end of text
var $stockConsumption = $('#stock_consumption'); var $stockConsumption = $('#stock_consumption');

View file

@ -1,13 +1,8 @@
/* global dropdownSelector GLOBAL_CONSTANTS I18n SmartAnnotation */ /* global dropdownSelector GLOBAL_CONSTANTS I18n SmartAnnotation formatDecimalValue */
var RepositoryStockValues = (function() { var RepositoryStockValues = (function() {
const UNIT_SELECTOR = '#repository-stock-value-units'; const UNIT_SELECTOR = '#repository-stock-value-units';
function formatDecimalValue(value, decimals) {
let regexp = decimals === 0 ? /[^-0-9]/g : /[^-0-9.]/g;
return value.replace(regexp, '').match(new RegExp(`^-?\\d*(\\.\\d{0,${decimals}})?`))[0];
}
function updateChangeAmount($element) { function updateChangeAmount($element) {
var currentAmount = parseFloat($element.data('currentAmount')); var currentAmount = parseFloat($element.data('currentAmount'));
var inputAmount = parseFloat($element.val()); var inputAmount = parseFloat($element.val());

View file

@ -0,0 +1,9 @@
/* eslint-disable no-unused-vars */
function formatDecimalValue(value, decimals) {
let decimalValue = value.replace(/[^-0-9.]/g, '');
if (decimals === 0) {
return decimalValue.split('.')[0];
}
return decimalValue.match(new RegExp(`^-?\\d*(\\.\\d{0,${decimals}})?`))[0];
}