From dad6322bacdac2f782fbe088e30e052e2dceea34 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 5 Nov 2017 11:29:17 +0100 Subject: [PATCH] Made some forms more convenient (input handling) --- views/consume.js | 1 + views/habittracking.js | 2 ++ views/inventory.js | 2 ++ views/purchase.js | 13 +++++++++++++ views/shoppinglistform.js | 2 ++ 5 files changed, 20 insertions(+) diff --git a/views/consume.js b/views/consume.js index 10616a74..a85e2d25 100644 --- a/views/consume.js +++ b/views/consume.js @@ -79,6 +79,7 @@ $('#product_id').on('change', function(e) $('#product_id_text_input').parent('.input-group').removeClass('has-error'); $('#product_id_text_input').closest('.form-group').removeClass('has-error'); $('#product-error').hide(); + $('#amount').focus(); } }, function(xhr) diff --git a/views/habittracking.js b/views/habittracking.js index 3ab0ddd2..b3fca302 100644 --- a/views/habittracking.js +++ b/views/habittracking.js @@ -47,6 +47,8 @@ $('#habit_id').on('change', function(e) $('#selected-habit-last-tracked-timeago').text($.timeago(habitDetails.last_tracked || '')); $('#selected-habit-tracked-count').text((habitDetails.tracked_count || '0')); + $('#tracked_time').focus(); + Grocy.EmptyElementWhenMatches('#selected-habit-last-tracked-timeago', 'NaN years ago'); }, function(xhr) diff --git a/views/inventory.js b/views/inventory.js index cb66dce2..29af91c3 100644 --- a/views/inventory.js +++ b/views/inventory.js @@ -84,6 +84,8 @@ $('#product_id').on('change', function(e) $('#new_amount').attr('not-equal', productDetails.stock_amount); $('#new_amount_qu_unit').text(productDetails.quantity_unit_stock.name); + $('#new_amount').focus(); + Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago'); Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago'); }, diff --git a/views/purchase.js b/views/purchase.js index 37fd62c9..be89dc7d 100644 --- a/views/purchase.js +++ b/views/purchase.js @@ -88,7 +88,12 @@ $('#product_id').on('change', function(e) { $('#best_before_date').val(moment().add(productDetails.product.default_best_before_days, 'days').format('YYYY-MM-DD')); $('#best_before_date').trigger('change'); + $('#amount').focus(); } + else + { + $('#best_before_date').focus(); + } Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago'); Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago'); @@ -295,6 +300,14 @@ $('#best_before_date').on('change', function(e) } }); +$('#best_before_date').on('keydown', function(e) +{ + if (e.keyCode === 13) //Enter + { + $('#best_before_date').trigger('change'); + } +}); + $('#best_before_date').on('keypress', function(e) { var element = $(e.target); diff --git a/views/shoppinglistform.js b/views/shoppinglistform.js index 6faeeaf3..9420c499 100644 --- a/views/shoppinglistform.js +++ b/views/shoppinglistform.js @@ -78,6 +78,8 @@ $('#product_id').on('change', function(e) $('#product_id_text_input').parent('.input-group').removeClass('has-error'); $('#product_id_text_input').closest('.form-group').removeClass('has-error'); $('#product-error').hide(); + + $('#amount').focus(); } }, function(xhr)