mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
Fixed recipeposform edit when "Only check if a single unit is in stock" is set (again closes #535)
This commit is contained in:
parent
7235d9c0c9
commit
5effa0c103
@ -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('<option value="' + qu.id + '" data-qu-factor="1">' + qu.name + '</option>');
|
||||
});
|
||||
|
||||
if (keepInitialQu)
|
||||
{
|
||||
Grocy.Components.ProductAmountPicker.SetQuantityUnit($("#qu_id").attr("data-initial-qu-id"));
|
||||
}
|
||||
|
||||
$(".input-group-productamountpicker").trigger("change");
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
<div class="form-group col-8 mb-1">
|
||||
<label for="qu_id">{{ $__t('Quantity unit') }}</label>
|
||||
<select required class="form-control input-group-productamountpicker" id="qu_id" name="qu_id" data-inital-qu-id="{{ $initialQuId }}">
|
||||
<select required class="form-control input-group-productamountpicker" id="qu_id" name="qu_id" data-initial-qu-id="{{ $initialQuId }}">
|
||||
<option></option>
|
||||
</select>
|
||||
<div class="invalid-feedback">{{ $__t('A quantity unit is required') }}</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user