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.
This commit is contained in:
1 parent
96d2ca2d4a
commit
b39c334fdf
1 file changed
+13
-6
@@ -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');
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user