From 595171afa5e6b1ba862e8a0225bb6c579c872046 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Fri, 3 May 2019 19:08:54 +0200 Subject: [PATCH] Properly show and handle that the new amount during inventory cannot equal the current stock amount (this now closes #224) --- localization/strings.pot | 3 +++ public/viewjs/components/numberpicker.js | 12 ++++++++++++ public/viewjs/inventory.js | 8 ++++---- views/inventory.blade.php | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/localization/strings.pot b/localization/strings.pot index 06b75d2e..570ff550 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -1203,3 +1203,6 @@ msgstr[1] "" msgid "Consume %s of %s" msgstr "" + +msgid "The amount cannot be lower than %s or equal %s" +msgstr "" diff --git a/public/viewjs/components/numberpicker.js b/public/viewjs/components/numberpicker.js index 61f38f59..5da1757d 100644 --- a/public/viewjs/components/numberpicker.js +++ b/public/viewjs/components/numberpicker.js @@ -13,3 +13,15 @@ $(".numberpicker-up-button").unbind('click').on("click", function() $(inputElement).trigger('keyup'); $(inputElement).trigger('change'); }); + +$(".numberpicker").on("keyup", function() +{ + if ($(this).data("not-equal") && !$(this).data("not-equal").toString().isEmpty() && $(this).data("not-equal") == $(this).val()) + { + $(this)[0].setCustomValidity("error"); + } + else + { + $(this)[0].setCustomValidity(""); + } +}); diff --git a/public/viewjs/inventory.js b/public/viewjs/inventory.js index bc57d3a9..f7a97d7d 100644 --- a/public/viewjs/inventory.js +++ b/public/viewjs/inventory.js @@ -84,26 +84,26 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) Grocy.Api.Get('stock/products/' + productId, function(productDetails) { - $('#new_amount').attr('not-equal', productDetails.stock_amount); + $('#new_amount').attr('data-not-equal', productDetails.stock_amount); $('#new_amount_qu_unit').text(productDetails.quantity_unit_stock.name); if (productDetails.product.allow_partial_units_in_stock == 1) { $("#new_amount").attr("min", "0.01"); $("#new_amount").attr("step", "0.01"); - $("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', 0.01.toLocaleString())); + $("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s or equal %s', 0.01.toLocaleString(), productDetails.stock_amount.toLocaleString())); } else { $("#new_amount").attr("min", "0"); $("#new_amount").attr("step", "1"); - $("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', '0')); + $("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s or equal %s', '0', productDetails.stock_amount.toLocaleString())); } if (productDetails.product.enable_tare_weight_handling == 1) { $("#new_amount").attr("min", productDetails.product.tare_weight); - $("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', parseFloat(productDetails.product.tare_weight).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 2 }))); + $("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s or equal %s', parseFloat(productDetails.product.tare_weight).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 2 }), productDetails.stock_amount.toLocaleString())); $("#tare-weight-handling-info").removeClass("d-none"); } else diff --git a/views/inventory.blade.php b/views/inventory.blade.php index a737033e..509b7155 100644 --- a/views/inventory.blade.php +++ b/views/inventory.blade.php @@ -23,7 +23,7 @@ 'min' => 0, 'value' => 1, 'invalidFeedback' => $__t('The amount cannot be lower than %s', '0'), - 'additionalAttributes' => 'data-notequal="notequal" not-equal="-1"', + 'additionalAttributes' => 'data-not-equal="-1"', 'additionalHtmlElements' => '
', 'additionalHtmlContextHelp' => '
' . $__t('Tare weight handling enabled - please weigh the whole container, the amount to be posted will be automatically calculcated') . '
' ))