diff --git a/public/viewjs/components/productamountpicker.js b/public/viewjs/components/productamountpicker.js index 0e34a587..652ab34e 100644 --- a/public/viewjs/components/productamountpicker.js +++ b/public/viewjs/components/productamountpicker.js @@ -21,20 +21,20 @@ Grocy.Components.ProductAmountPicker.Reload = function(productId, destinationQuI }); } - if (!Grocy.Components.ProductAmountPicker.InitalValueSet || forceInitialDisplayQu) + if (!Grocy.Components.ProductAmountPicker.InitialValueSet || forceInitialDisplayQu) { - $("#qu_id").val($("#qu_id").attr("data-inital-qu-id")); + $("#qu_id").val($("#qu_id").attr("data-initial-qu-id")); } - if (!Grocy.Components.ProductAmountPicker.InitalValueSet) + if (!Grocy.Components.ProductAmountPicker.InitialValueSet) { var convertedAmount = $("#display_amount").val() * $("#qu_id option:selected").attr("data-qu-factor"); $("#display_amount").val(convertedAmount); - Grocy.Components.ProductAmountPicker.InitalValueSet = true; + Grocy.Components.ProductAmountPicker.InitialValueSet = true; } - if (conversionsForProduct.length === 1) + if (conversionsForProduct.length === 1 && !forceInitialDisplayQu) { $("#qu_id").val($("#qu_id option:first").val()); } @@ -42,12 +42,12 @@ Grocy.Components.ProductAmountPicker.Reload = function(productId, destinationQuI $(".input-group-productamountpicker").trigger("change"); } -Grocy.Components.ProductAmountPicker.SetQuantityUnit = function() +Grocy.Components.ProductAmountPicker.SetQuantityUnit = function(quId) { $("#qu_id").val(quId); } -Grocy.Components.ProductAmountPicker.AllowAnyQu = function(quId) +Grocy.Components.ProductAmountPicker.AllowAnyQu = function(keepInitialQu = false) { Grocy.Components.ProductAmountPicker.AllowAnyQuEnabled = true; @@ -57,6 +57,11 @@ Grocy.Components.ProductAmountPicker.AllowAnyQu = function(quId) $("#qu_id").append(''); }); + if (keepInitialQu) + { + Grocy.Components.ProductAmountPicker.SetQuantityUnit($("#qu_id").attr("data-initial-qu-id")); + } + $(".input-group-productamountpicker").trigger("change"); } diff --git a/public/viewjs/recipeposform.js b/public/viewjs/recipeposform.js index 7d228155..b7f1dc9e 100644 --- a/public/viewjs/recipeposform.js +++ b/public/viewjs/recipeposform.js @@ -55,7 +55,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) { Grocy.RecipePosFormProductChangeCount++; - if (Grocy.RecipePosFormProductChangeCount < 3) // This triggers twice on inital page load, however + if (Grocy.RecipePosFormProductChangeCount < 3) // This triggers twice on initial page load, however { Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id, true); } @@ -139,7 +139,7 @@ $("#only_check_single_unit_in_stock").on("click", function() $("#display_amount").attr("min", "0.01"); $("#display_amount").attr("step", "0.01"); $("#display_amount").parent().find(".invalid-feedback").text(__t("This cannot be negative")); - Grocy.Components.ProductAmountPicker.AllowAnyQu(); + Grocy.Components.ProductAmountPicker.AllowAnyQu(true); Grocy.FrontendHelpers.ValidateForm("recipe-pos-form"); } else @@ -153,6 +153,7 @@ $("#only_check_single_unit_in_stock").on("click", function() } }); -// Click twice to trigger on-click but not change the actual checked state -$("#only_check_single_unit_in_stock").click(); -$("#only_check_single_unit_in_stock").click(); +if ($("#only_check_single_unit_in_stock").prop("checked")) +{ + Grocy.Components.ProductAmountPicker.AllowAnyQu(true); +} diff --git a/views/components/productamountpicker.blade.php b/views/components/productamountpicker.blade.php index 10c245e7..36400119 100644 --- a/views/components/productamountpicker.blade.php +++ b/views/components/productamountpicker.blade.php @@ -20,7 +20,7 @@