Skip to content

Commit 7a083b4

Browse files
authored
Fix: prevent double submit on select change + blur in inline edit (#1255)
HTMLSelectElement was submitting twice (once on change, once on blur). Added a submitted guard flag so only the first event triggers submitCell.
1 parent f39da7e commit 7a083b4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

assets/plugins/features/editable.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,19 @@ export class EditablePlugin implements DatagridPlugin {
110110
"input, textarea, select"
111111
)
112112
.forEach(el => {
113-
if (!(el instanceof HTMLSelectElement)) {
113+
if (el instanceof HTMLSelectElement) {
114+
let submitted = false;
115+
const submitOnce = () => {
116+
if (submitted) return;
117+
submitted = true;
118+
submitCell(el);
119+
};
120+
el.addEventListener("change", submitOnce);
121+
el.addEventListener("blur", submitOnce);
122+
} else {
114123
el.addEventListener("blur", () => submitCell(el));
115124
}
116-
125+
117126
el.addEventListener("keydown", e => {
118127
if (isEnter(e as KeyboardEvent)) {
119128
e.stopPropagation();
@@ -129,9 +138,6 @@ export class EditablePlugin implements DatagridPlugin {
129138
}
130139
});
131140

132-
if (el instanceof HTMLSelectElement) {
133-
el.addEventListener("change", () => submitCell(el));
134-
}
135141
});
136142
}
137143
});

0 commit comments

Comments
 (0)