Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions assets/plugins/features/autosubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,20 @@ export class AutosubmitPlugin implements DatagridPlugin {
);
}

submitEl.addEventListener(
"keyup",
debounce(e => {
// Ignore keys such as alt, ctrl, etc, F-keys... (when enter is not pressed)
if (!isEnter(e) && (isInKeyRange(e, 9, 40) || isFunctionKey(e))) {
return;
}

return datagrid.ajax.submitForm(form);
})
);
const debouncedSubmit = debounce(() => datagrid.ajax.submitForm(form));
submitEl.addEventListener("keyup", (e) => {
// Enter submits immediately, no debounce wait.
if (isEnter(e)) {
datagrid.ajax.submitForm(form);
return;
}
// Skip alt/ctrl/etc and F-keys here, not inside debounce — a late
// modifier keyup would otherwise overwrite the debounced submit's target.
if (isInKeyRange(e, 9, 40) || isFunctionKey(e)) {
return;
}
debouncedSubmit();
});
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions assets/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export function isPromise<T = any>(p: any): p is Promise<T> {

export function isInKeyRange(e: KeyboardEvent, min: number, max: number): boolean {
if (e.key.length !== 1) { // Named keys (Tab, Shift, ArrowLeft, etc.) are always considered in range
if (e.key === 'Backspace' || e.key === 'Delete') {
return false; // Editing keys change the input value and should still trigger autosubmit
if (e.key === 'Backspace' || e.key === 'Delete' || e.key === 'Unidentified') {
return false; // Editing keys (and the virtual-keyboard placeholder) change the input value and should still trigger autosubmit
}
return true;
}
Expand Down
Loading