Skip to content

Commit 27d84f1

Browse files
radimvaculikf3l1x
authored andcommitted
Fix: Use event delegation for confirm to survive AJAX snippet updates (#1250)
Closes #1250
1 parent 30b1bef commit 27d84f1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

assets/plugins/features/confirm.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ export class ConfirmPlugin implements DatagridPlugin {
3232
onDatagridInit(datagrid: Datagrid): boolean {
3333
this.datagrid = datagrid;
3434

35-
const confirmElements = datagrid.el.querySelectorAll<HTMLElement>(`[${ConfirmAttribute}]:not(.ajax)`);
36-
confirmElements.forEach(el => el.addEventListener("click", e => this.handleClick(el, e)));
35+
datagrid.el.addEventListener("click", e => {
36+
const target = e.target as HTMLElement;
37+
const confirmEl = target.closest<HTMLElement>(`[${ConfirmAttribute}]:not(.ajax)`);
38+
if (confirmEl) {
39+
this.handleClick(confirmEl, e);
40+
}
41+
});
3742

3843
datagrid.ajax.addEventListener("interact", e => {
3944
const target = e.detail.element;

0 commit comments

Comments
 (0)