From b39c334fdfab1e7367198cdceae42d358c7bf0fd Mon Sep 17 00:00:00 2001 From: mileswa1q22 Date: Tue, 31 Mar 2026 19:16:46 -0500 Subject: [PATCH] Handle position edits on focusout Stop performing item repositioning during the primary input handler and instead handle position changes on focusout. Non-position fields are updated live on input and mark the form as having unsaved changes. A new tbody focusout listener moves the item and re-renders the admin table when a position field loses focus, and also sets the unsaved status. --- app.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index bb58bdf..d6038d4 100644 --- a/app.js +++ b/app.js @@ -479,12 +479,19 @@ const field = target.getAttribute('data-field'); const index = Number(target.getAttribute('data-index')); if(!field || Number.isNaN(index) || !items[index]) return; - if(field === 'position'){ - moveItemToPosition(index, target.value); - renderAdminTable(); - }else{ - items[index][field] = target.value; - } + if(field === 'position') return; + items[index][field] = target.value; + setStatus('Unsaved changes'); + }); + + tbody.addEventListener('focusout', function(event){ + const target = event.target; + if(!(target instanceof HTMLElement)) return; + const field = target.getAttribute('data-field'); + const index = Number(target.getAttribute('data-index')); + if(field !== 'position' || Number.isNaN(index) || !items[index]) return; + moveItemToPosition(index, target.value); + renderAdminTable(); setStatus('Unsaved changes'); });