mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-04 19:53:19 +08:00
Fix decimal render function [SCI-6742] (#4037)
Co-authored-by: Anton <anton@scinote.net>
This commit is contained in:
parent
4daf01feee
commit
918a11a0b0
3 changed files with 11 additions and 12 deletions
|
@ -1,13 +1,8 @@
|
|||
/* global SmartAnnotation I18n MyModuleRepositories GLOBAL_CONSTANTS */
|
||||
/* global SmartAnnotation I18n MyModuleRepositories GLOBAL_CONSTANTS formatDecimalValue */
|
||||
var MyModuleStockConsumption = (function() {
|
||||
const CONSUMPTION_MODAL = '#consumeRepositoryStockValueModal';
|
||||
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() {
|
||||
// focus and move cursor to end of text
|
||||
var $stockConsumption = $('#stock_consumption');
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
/* global dropdownSelector GLOBAL_CONSTANTS I18n SmartAnnotation */
|
||||
/* global dropdownSelector GLOBAL_CONSTANTS I18n SmartAnnotation formatDecimalValue */
|
||||
|
||||
var RepositoryStockValues = (function() {
|
||||
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) {
|
||||
var currentAmount = parseFloat($element.data('currentAmount'));
|
||||
var inputAmount = parseFloat($element.val());
|
||||
|
|
9
app/assets/javascripts/sitewide/decimal_formatter.js
Normal file
9
app/assets/javascripts/sitewide/decimal_formatter.js
Normal 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];
|
||||
}
|
Loading…
Reference in a new issue