diff --git a/changelog/56_UNRELEASED_2020-xx-xx.md b/changelog/56_UNRELEASED_2020-xx-xx.md index dfd9fe6c..cf886726 100644 --- a/changelog/56_UNRELEASED_2020-xx-xx.md +++ b/changelog/56_UNRELEASED_2020-xx-xx.md @@ -12,6 +12,9 @@ - Fixed that when editing a recipe ingredient which had "Only check if a single unit is in stock" set, not any quantity unit could be picked and the amount stayed empty - Fixed that when reloading the "new recipe"-page (or when it gets auto-reloaded due to "Auto reload on external changes" is enabled), for each reload a new recipe was created +### Meal plan improvements +- Improved that all add-dialogs can be submitted by using `ENTER` and that the next input is automatically selected after selecting a recipe/product + ### General & other improvements/fixes - Optimized the top navbar height to waste less space - Fixed that the "contextual time ago" of date/time pickers was not displayed diff --git a/public/viewjs/mealplan.js b/public/viewjs/mealplan.js index 4bc4448f..94912fbb 100644 --- a/public/viewjs/mealplan.js +++ b/public/viewjs/mealplan.js @@ -277,6 +277,7 @@ $(document).on("click", ".add-recipe-button", function(e) $("#add-recipe-modal-title").text(__t("Add recipe to %s", day.toString())); $("#day").val(day.toString()); + $("#recipe_servings").val(1); Grocy.Components.RecipePicker.Clear(); $("#add-recipe-modal").modal("show"); Grocy.FrontendHelpers.ValidateForm("add-recipe-form"); @@ -407,7 +408,7 @@ $('#save-add-product-button').on('click', function(e) ); }); -Grocy.Components.RecipePicker.GetInputElement().keydown(function(event) +$('#add-recipe-form input').keydown(function (event) { if (event.keyCode === 13) //Enter { @@ -424,6 +425,23 @@ Grocy.Components.RecipePicker.GetInputElement().keydown(function(event) } }); +$('#add-product-form input').keydown(function (event) +{ + if (event.keyCode === 13) //Enter + { + event.preventDefault(); + + if (document.getElementById("add-product-form").checkValidity() === false) //There is at least one validation error + { + return false; + } + else + { + $("#save-add-product-button").click(); + } + } +}); + $(document).on("keydown", "#servings", function(e) { if (event.keyCode === 13) //Enter @@ -629,10 +647,11 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) Grocy.Api.Get('stock/products/' + productId, function(productDetails) { - Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id, true); + Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id); $('#display_amount').val(1); $('#display_amount').focus(); + $('#display_amount').select(); $(".input-group-productamountpicker").trigger("change"); Grocy.FrontendHelpers.ValidateForm('add-product-form'); }, @@ -657,3 +676,18 @@ function UndoStockTransaction(transactionId) } ); }; + +Grocy.Components.RecipePicker.GetPicker().on('change', function(e) +{ + var recipeId = $(e.target).val(); + + if (recipeId) + { + // Does not work (clears the RecipePicker) when done immediately, don't know why... + setTimeout(function() + { + $("#recipe_servings").focus(); + $("#recipe_servings").select(); + }, 200); + } +});