From 235b96d17fecbce8aeae483905a9d34144ec7d9f Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 17 Oct 2020 10:52:25 +0200 Subject: [PATCH] Fixed recipe ingredient initial QU (fixes #1060) --- public/viewjs/recipeposform.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/public/viewjs/recipeposform.js b/public/viewjs/recipeposform.js index e02d90ea..2a2dad66 100644 --- a/public/viewjs/recipeposform.js +++ b/public/viewjs/recipeposform.js @@ -1,4 +1,4 @@ -Grocy.RecipePosFormProductChangeCount = 0; +Grocy.RecipePosFormInitialLoadDone = false; $('#save-recipe-pos-button').on('click', function(e) { @@ -53,9 +53,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) Grocy.Api.Get('stock/products/' + productId, function(productDetails) { - Grocy.RecipePosFormProductChangeCount++; - - if (Grocy.RecipePosFormProductChangeCount < 3) // This triggers twice on initial page load, however + if (!Grocy.RecipePosFormInitialLoadDone) { Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id, true); } @@ -82,13 +80,14 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) $("#not_check_stock_fulfillment").prop("checked", productDetails.product.not_check_stock_fulfillment_for_recipes == 1); } - if (!$("#only_check_single_unit_in_stock").prop("checked")) + if (!$("#only_check_single_unit_in_stock").prop("checked") && Grocy.RecipePosFormInitialLoadDone) { Grocy.Components.ProductAmountPicker.SetQuantityUnit(productDetails.quantity_unit_stock.id); } $('#display_amount').focus(); Grocy.FrontendHelpers.ValidateForm('recipe-pos-form'); + Grocy.RecipePosFormInitialLoadDone = true; }, function(xhr) { @@ -106,6 +105,11 @@ if (Grocy.Components.ProductPicker.InProductAddWorkflow() === false) } Grocy.Components.ProductPicker.GetPicker().trigger('change'); +if (Grocy.EditMode == "create") +{ + Grocy.RecipePosFormInitialLoadDone = true; +} + $('#display_amount').on('focus', function(e) { if (Grocy.Components.ProductPicker.GetValue().length === 0)