From 196024a454b7f0b238d0ea93c20f55b50486e17e Mon Sep 17 00:00:00 2001 From: ralf Date: Thu, 6 Oct 2022 13:55:24 +0200 Subject: [PATCH] stopping buttons in dialog from submitting it to server-side --- api/js/etemplate/Et2Button/ButtonMixin.ts | 2 +- api/js/etemplate/Et2Dialog/Et2Dialog.ts | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/api/js/etemplate/Et2Button/ButtonMixin.ts b/api/js/etemplate/Et2Button/ButtonMixin.ts index f5b39834cc..7a2f0cf7ee 100644 --- a/api/js/etemplate/Et2Button/ButtonMixin.ts +++ b/api/js/etemplate/Et2Button/ButtonMixin.ts @@ -180,7 +180,7 @@ export const ButtonMixin = (superclass : T) => class exte _handleClick(event : MouseEvent) : boolean { // ignore click on readonly button - if(this.disabled || this.readonly) + if(this.disabled || this.readonly || event.defaultPrevented) { event.preventDefault(); event.stopImmediatePropagation(); diff --git a/api/js/etemplate/Et2Dialog/Et2Dialog.ts b/api/js/etemplate/Et2Dialog/Et2Dialog.ts index 64e63c6305..4b69462adc 100644 --- a/api/js/etemplate/Et2Dialog/Et2Dialog.ts +++ b/api/js/etemplate/Et2Dialog/Et2Dialog.ts @@ -414,14 +414,15 @@ export class Et2Dialog extends Et2Widget(ScopedElementsMixin(SlotMixin(LionDialo // @ts-ignore this._button_id = ev.target?.getAttribute("button_id") ? parseInt(ev.target?.getAttribute("button_id")) : (ev.target?.getAttribute("id") || null); + // we always need to stop the event as otherwise the result would be submitted to server-side eT2 handler + // which does not know what to do with it, as the dialog was initiated from client-side (no eT2 request) + ev.preventDefault(); + ev.stopPropagation(); + // Handle anything bound via et2 onclick property try { let et2_widget_result = super._handleClick(ev); - // we always need to stop the event as otherwise the result would be submitted to server-side eT2 handler - // which does not know what to do with it, as the dialog was initiated from client-side (no eT2 request) - ev.preventDefault(); - ev.stopPropagation(); if(et2_widget_result === false) { return false; @@ -432,15 +433,10 @@ export class Et2Dialog extends Et2Widget(ScopedElementsMixin(SlotMixin(LionDialo console.log(e); } - // Callback expects (button_id, value) try { let callback_result = this.callback ? this.callback(this._button_id, this.value, ev) : true; - // we always need to stop the event as otherwise the result would be submitted to server-side eT2 handler - // which does not know what to do with it, as the dialog was initiated from client-side (no eT2 request) - ev.preventDefault(); - ev.stopPropagation(); if(callback_result === false) { return false;