From 086a4aea47449095b3e03f387ea4ab2a7b9e8d52 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Mon, 21 Sep 2020 23:05:58 +0200 Subject: [PATCH] basics of shopping list working --- cookbook/templates/shopping_list.html | 33 +++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/cookbook/templates/shopping_list.html b/cookbook/templates/shopping_list.html index 4902f0af3..ad8dd298a 100644 --- a/cookbook/templates/shopping_list.html +++ b/cookbook/templates/shopping_list.html @@ -395,23 +395,26 @@ }, addEntry: function () { - this.shopping_list.entries.push({ - 'list_recipe': null, - 'food': this.new_entry.food, - 'unit': ((this.new_entry.unit !== undefined) ? this.new_entry.unit : {'name': ''}), - 'amount': parseFloat(this.new_entry.amount), - 'order': 0, - 'checked': false - }) + if (this.new_entry.food !== undefined) { + this.shopping_list.entries.push({ + 'list_recipe': null, + 'food': this.new_entry.food, + 'unit': ((this.new_entry.unit !== undefined) ? this.new_entry.unit : {'name': ''}), + 'amount': parseFloat(this.new_entry.amount), + 'order': 0, + 'checked': false + }) - this.new_entry = { - unit: undefined, - amount: undefined, - food: undefined, + this.new_entry = { + unit: undefined, + amount: undefined, + food: undefined, + } + + this.$refs.new_entry_amount.focus(); + } else { + this.makeToast('{% trans 'Error' %}', '{% trans 'Please enter a valid food' %}', 'danger') } - - this.$refs.new_entry_amount.focus(); - }, getRecipes: function () { let url = "{% url 'api:recipe-list' %}?limit=5&internal=true"