diff --git a/static/form.html b/static/form.html index b8a11f4..a5de3f2 100644 --- a/static/form.html +++ b/static/form.html @@ -10,7 +10,7 @@

in?

- + (use ? as placeholder for next available number) diff --git a/static/form.js b/static/form.js index b9dca54..7ef51d9 100644 --- a/static/form.js +++ b/static/form.js @@ -65,8 +65,8 @@ function knownTypes() { } function save() { - item = { - id: document.getElementById('id').value || null, + const item = { + id: document.getElementById('id').value || '', is_in: document.getElementById('is_in').value || null, coords_bl: document.getElementById('coords_bl').value || null, coords_tr: document.getElementById('coords_tr').value || null, @@ -77,6 +77,17 @@ function save() { hidden: document.getElementById('hidden').checked, } + if (item.id.includes('?')) { + let n = 1; + while (true) { + const candidate = item.id.replace('?', n++); + if (!Object.keys(items).includes(candidate)) { + item.id = candidate; + break; + } + } + } + if (items[item.id]) { if (!id || (id && id != item.id)) { alert(`ID ${item.id} exists. Please chose a different ID or edit the existing ${item.id} item!`);