From 0dc37fb361b8b2918eb2554812fa6fdfb6851003 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 4 Jul 2021 17:36:44 +0200 Subject: [PATCH] Don't allow a min. stock amount for child products when the parent has "Accumulate sub products min. stock amount" set (references #1409) --- public/viewjs/productform.js | 32 ++++++++++++++++++++++++++++++++ views/productform.blade.php | 2 ++ 2 files changed, 34 insertions(+) diff --git a/public/viewjs/productform.js b/public/viewjs/productform.js index 25de95ea..88a8051e 100644 --- a/public/viewjs/productform.js +++ b/public/viewjs/productform.js @@ -505,4 +505,36 @@ else if (Grocy.EditMode === 'create') } } +Grocy.Components.ProductPicker.GetPicker().on('change', function(e) +{ + var parentProductId = $(e.target).val(); + + if (parentProductId) + { + Grocy.Api.Get('objects/products/' + parentProductId, + function(parentProduct) + { + if (BoolVal(parentProduct.cumulate_min_stock_amount_of_sub_products)) + { + + $("#min_stock_amount").attr("disabled", ""); + } + else + { + $('#min_stock_amount').removeAttr("disabled"); + } + }, + function(xhr) + { + console.error(xhr); + } + ); + } + else + { + $('#min_stock_amount').removeAttr("disabled"); + } +}); + Grocy.FrontendHelpers.ValidateForm("product-form"); +Grocy.Components.ProductPicker.GetPicker().trigger("change"); diff --git a/views/productform.blade.php b/views/productform.blade.php index f7b23e1e..9c53393a 100644 --- a/views/productform.blade.php +++ b/views/productform.blade.php @@ -606,8 +606,10 @@ title="{{ $__t('grocycode is a unique referer to this product in your grocy instance - print it onto a label and scan it like any other barcode') }}">

+ @if($mode == 'edit') + @endif