diff --git a/controllers/RecipesController.php b/controllers/RecipesController.php index 8f6cd3da..93b20cd3 100644 --- a/controllers/RecipesController.php +++ b/controllers/RecipesController.php @@ -110,6 +110,7 @@ class RecipesController extends BaseController return $this->AppContainer->view->render($response, 'recipeposform', [ 'mode' => 'create', 'recipe' => $this->Database->recipes($args['recipeId']), + 'recipePos' => new \stdClass(), 'products' => $this->Database->products()->orderBy('name'), 'quantityUnits' => $this->Database->quantity_units()->orderBy('name'), 'quantityUnitConversionsResolved' => $this->Database->quantity_unit_conversions_resolved() diff --git a/public/viewjs/components/productamountpicker.js b/public/viewjs/components/productamountpicker.js index 7e60c5b2..ced3987c 100644 --- a/public/viewjs/components/productamountpicker.js +++ b/public/viewjs/components/productamountpicker.js @@ -3,9 +3,10 @@ Grocy.Components.ProductAmountPicker.AllowAnyQuEnabled = false; Grocy.Components.ProductAmountPicker.Reload = function(productId, destinationQuId, forceInitialDisplayQu = false) { + var conversionsForProduct = FindAllObjectsInArrayByPropertyValue(Grocy.QuantityUnitConversionsResolved, 'product_id', productId); + if (!Grocy.Components.ProductAmountPicker.AllowAnyQuEnabled) { - var conversionsForProduct = FindAllObjectsInArrayByPropertyValue(Grocy.QuantityUnitConversionsResolved, 'product_id', productId); $("#qu_id").find("option").remove().end(); $("#qu_id").attr("data-destination-qu-name", FindObjectInArrayByPropertyValue(Grocy.QuantityUnits, 'id', destinationQuId).name); conversionsForProduct.forEach(conversion => @@ -27,6 +28,11 @@ Grocy.Components.ProductAmountPicker.Reload = function(productId, destinationQuI Grocy.Components.ProductAmountPicker.InitalValueSet = true; } + if (conversionsForProduct.length === 1) + { + $("#qu_id").val($("#qu_id option:first").val()); + } + $(".input-group-productamountpicker").trigger("change"); } diff --git a/views/components/productpicker.blade.php b/views/components/productpicker.blade.php index 5352d7ad..ecef52c9 100644 --- a/views/components/productpicker.blade.php +++ b/views/components/productpicker.blade.php @@ -10,6 +10,7 @@ @php if(!isset($label)) { $label = 'Product'; } @endphp @php if(!isset($disabled)) { $disabled = false; } @endphp @php if(empty($hint)) { $hint = ''; } @endphp +@php if(empty($nextInputSelector)) { $nextInputSelector = ''; } @endphp