Skip to content

Commit d398d38

Browse files
committed
Fix: autosubmit dropped after modifier or virtual-keyboard keyup
Move the skip-keys predicate out of the debounce wrapper so a late modifier or nav keyup can't overwrite the pending submit's target event and silence submitForm. Also let Unidentified through the predicate — virtual keyboards dispatch it. Bind Enter to immediate submit.
1 parent e5faff0 commit d398d38

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

assets/plugins/features/autosubmit.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,20 @@ export class AutosubmitPlugin implements DatagridPlugin {
6666
);
6767
}
6868

69-
submitEl.addEventListener(
70-
"keyup",
71-
debounce(e => {
72-
// Ignore keys such as alt, ctrl, etc, F-keys... (when enter is not pressed)
73-
if (!isEnter(e) && (isInKeyRange(e, 9, 40) || isFunctionKey(e))) {
74-
return;
75-
}
76-
77-
return datagrid.ajax.submitForm(form);
78-
})
79-
);
69+
const debouncedSubmit = debounce(() => datagrid.ajax.submitForm(form));
70+
submitEl.addEventListener("keyup", (e) => {
71+
// Enter submits immediately, no debounce wait.
72+
if (isEnter(e)) {
73+
datagrid.ajax.submitForm(form);
74+
return;
75+
}
76+
// Skip alt/ctrl/etc and F-keys here, not inside debounce — a late
77+
// modifier keyup would otherwise overwrite the debounced submit's target.
78+
if (isInKeyRange(e, 9, 40) || isFunctionKey(e)) {
79+
return;
80+
}
81+
debouncedSubmit();
82+
});
8083
}
8184
});
8285
}

assets/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export function isPromise<T = any>(p: any): p is Promise<T> {
77

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

0 commit comments

Comments
 (0)