From fb9ce4efbc39497cb219fe71d07b26277e0bacee Mon Sep 17 00:00:00 2001 From: Giga Chubinidze Date: Thu, 4 Apr 2024 06:03:49 +0400 Subject: [PATCH] Enable adding negative numbers for Stock [SCI-10533] --- .../vue/repository_row/manage_stock_value_modal.vue | 2 +- app/javascript/vue/shared/legacy/input.vue | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/javascript/vue/repository_row/manage_stock_value_modal.vue b/app/javascript/vue/repository_row/manage_stock_value_modal.vue index 65c435a85..b33f2ae46 100644 --- a/app/javascript/vue/repository_row/manage_stock_value_modal.vue +++ b/app/javascript/vue/repository_row/manage_stock_value_modal.vue @@ -46,6 +46,7 @@ :label="i18n.t('repository_stock_values.manage_modal.amount')" :required="true" :min="0" + :negativeNumbersEnabled="this.operation == 'set'" :error="errors.amount" /> @@ -252,7 +253,6 @@ export default { const newErrors = {}; if (!this.unit) { newErrors.unit = I18n.t('repository_stock_values.manage_modal.unit_error'); } if (!this.amount) { newErrors.amount = I18n.t('repository_stock_values.manage_modal.amount_error'); } - if (this.amount && this.amount < 0) { newErrors.amount = I18n.t('repository_stock_values.manage_modal.negative_error'); } if (this.reminderEnabled && !this.lowStockTreshold) { newErrors.tresholdAmount = I18n.t('repository_stock_values.manage_modal.amount_error'); } if (this.comment && this.comment.length > 255) { newErrors.comment = I18n.t('repository_stock_values.manage_modal.comment_limit'); } this.errors = newErrors; diff --git a/app/javascript/vue/shared/legacy/input.vue b/app/javascript/vue/shared/legacy/input.vue index cec2344e4..7bd94748c 100644 --- a/app/javascript/vue/shared/legacy/input.vue +++ b/app/javascript/vue/shared/legacy/input.vue @@ -38,7 +38,8 @@ export default { error: { type: String, required: false }, min: { type: [String, Number] }, max: { type: [String, Number] }, - blockInvalidInput: { type: Boolean, default: true } + blockInvalidInput: { type: Boolean, default: true }, + negativeNumbersEnabled: {type: Boolean, required: false } }, data() { return { @@ -56,6 +57,13 @@ export default { }, computed: { pattern() { + if (this.negativeNumbersEnabled) { + if (this.type === 'number' && this.decimals) { + return `-?[0-9]+([\\.]-?[0-9]{0,${this.decimals}})?`; + } else if (this.type === 'number') { + return '-?[0-9]+'; + } + } if (this.type === 'number' && this.decimals) { return `[0-9]+([\\.][0-9]{0,${this.decimals}})?`; } else if (this.type === 'number') {