From 86f2c9d89ca5bcc763cd8f70b5ff8fcc1d50d7d7 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Mon, 16 Mar 2020 23:08:52 +0100 Subject: [PATCH] cleand up and fixed ingredient edit table --- .../templates/forms/edit_internal_recipe.html | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/cookbook/templates/forms/edit_internal_recipe.html b/cookbook/templates/forms/edit_internal_recipe.html index 0dc6481b..fbb718ce 100644 --- a/cookbook/templates/forms/edit_internal_recipe.html +++ b/cookbook/templates/forms/edit_internal_recipe.html @@ -115,9 +115,9 @@ let ingredients = {{ ingredients|safe }} - ingredients.forEach(function (cur, i) { - cur.delete = false - }); + ingredients.forEach(function (cur, i) { + cur.delete = false + }); let data = ingredients; @@ -165,15 +165,6 @@ }, {title: "id", field: "id", visible: false} ], - dataEdited: function (data) { - $('#id_ingredients').val(JSON.stringify(data)) - - data.forEach(function (cur, i) { - if (cur.delete) { - table.deleteRow(cur.id); - } - }) - }, cellClick: function (e, cell) { if (cell._cell.column.definition.editor === "input") { input = cell.getElement().childNodes[0]; @@ -183,6 +174,12 @@ }, }); + // save ingredient data before submitting form + $('#id_form').submit(function () { + $('#id_ingredients').val(JSON.stringify(table.getData())); + return true; + }); + // load initial value $('#id_ingredients').val(JSON.stringify(data))