From 005f6317931e50a48da42558e0356b336b426f91 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Wed, 6 Nov 2024 20:14:42 -0500 Subject: [PATCH] - Working on ui-popup adding some features based on FORM inside of it --- asset/webcomponent/module/ui-popup.js | 39 ++++++++++++++++++++------- view/webcomponent/ui-popup.phtml | 2 +- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/asset/webcomponent/module/ui-popup.js b/asset/webcomponent/module/ui-popup.js index 0f3d82b..395f869 100644 --- a/asset/webcomponent/module/ui-popup.js +++ b/asset/webcomponent/module/ui-popup.js @@ -68,8 +68,6 @@ class UiPopup extends Webcomponent { trigger.dispatchEvent(ev); break; - - case 8: // BACKSPACE case 27: // ESC trigger = this.querySelector('[action="close"]'); ev = new CustomEvent('click', { trigger: trigger } ); @@ -116,10 +114,19 @@ class UiPopup extends Webcomponent { case "confirm": case "yes": case "ok": - this.actionFollowLink(element) || - this.actionClickButton(element) || - this.actionSendForm(element) || - this.actionSendForm(this.trigger); + let retval = this.actionFollowLink(element) || + this.actionClickButton(element); + if (! retval) { + retval = this.actionSendForm(element) || + this.actionSendForm(this.trigger) || + this.actionSendForm(element.closest('ui-popup').querySelector('form')); + + if ( ! retval ) { + throw "No action to trigger automatically on Popup confirmation."; + } + + break; + } case "cancel": case "no": @@ -189,18 +196,30 @@ class UiPopup extends Webcomponent { } actionSendForm(element) { + if ( ! element ) { + return false; + } + //if ( element.getAttribute('send-form') !== null ) { //let form = this.trigger.tagName === "FORM" ? this.trigger : this.trigger.closest('FORM'); let form = element.tagName === "FORM" ? element : element.closest('FORM'); if ( form ) { - form.submit(); +// form.addEventListener("submit", e => this.hide); + + let submitBtn = form.querySelector("button[type='submit']"); + + if (submitBtn) { + submitBtn.click(); + } + else { + form.submit(); + } return true; } - else { - throw "A send-form action was set on a popup where the trigger as no parent form."; - } + + return false; //} } diff --git a/view/webcomponent/ui-popup.phtml b/view/webcomponent/ui-popup.phtml index 52ead62..2d40a98 100644 --- a/view/webcomponent/ui-popup.phtml +++ b/view/webcomponent/ui-popup.phtml @@ -1,5 +1,5 @@