From: Christian Heller Date: Mon, 3 Mar 2025 01:26:52 +0000 (+0100) Subject: In /edit_structured, add "add line" buttons for all lines. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdb.prefix%7D%7D/static/test.html?a=commitdiff_plain;h=f7685622568bed7c7bf3e08982aaefa5ef2d4b91;p=ledgplom In /edit_structured, add "add line" buttons for all lines. --- diff --git a/src/templates/edit_structured.tmpl b/src/templates/edit_structured.tmpl index 70df624..959574c 100644 --- a/src/templates/edit_structured.tmpl +++ b/src/templates/edit_structured.tmpl @@ -132,10 +132,16 @@ function update_form() { } add_td_input('comment', dat_line.comment, 40); - // delete button - td_del = add_td(tr); + // line deletion and addition buttons + td_add_del = add_td(tr); + add_button(td_add_del, 'add new', false, function() { + new_line = {error: '', comment: '', booking_line: {account: '', amount: '', currency: ''}}; + dat_lines.splice(i + 1, 0, new_line); + }); if (i > 0) { - add_button(td_del, 'delete', i > 0 ? false : true, function() { dat_lines.splice(i, 1); }); + add_button(td_add_del, 'delete', i > 0 ? false : true, function() { + dat_lines.splice(i, 1); + }); } // add error explanation row if necessary @@ -149,15 +155,6 @@ function update_form() { } } - // add "add line" row - const tr = document.createElement("tr"); - table.appendChild(tr); - const td = add_td(tr, 5); - add_button(td, 'add line', false, function() { - new_line = {error: '', comment: '', booking_line: {account: '', amount: '', currency: ''}}; - dat_lines.push(new_line); - }); - // make all rows alternate background color for better readability Array.from(table.rows).forEach((tr) => { tr.classList.add('alternating');