From 649976f6637e78a347f4a938f7977e4f2a9a8235 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 17 Aug 2022 10:52:57 +0200 Subject: [PATCH] fix missing script --- _config/pure-modal.yml | 3 ++- src/PureModalAction.php | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/_config/pure-modal.yml b/_config/pure-modal.yml index 92a4bd2..1f3d726 100644 --- a/_config/pure-modal.yml +++ b/_config/pure-modal.yml @@ -2,6 +2,7 @@ Name: pure-modal --- LeKoala\PureModal\PureModal: - move_modal_to_body: true + move_modal_to_body: false overlay_triggers_close: true compute_iframe_height: false + edit_form_id: 'Form_ItemEditForm' diff --git a/src/PureModalAction.php b/src/PureModalAction.php index 107e916..5404395 100644 --- a/src/PureModalAction.php +++ b/src/PureModalAction.php @@ -72,12 +72,30 @@ public function getOverlayTriggersClose() return PureModal::getOverlayTriggersCloseConfig(); } + /** + * If the modal is in the body, it needs to go back to the form to submit properly + * @return string + */ + public function SubmitOnClickScript() + { + if (!PureModal::getMoveModalScript()) { + return ''; + } + $formId = PureModal::config()->edit_form_id; + return "var f=document.getElementById('$formId');f.appendChild(this.closest('.pure-modal'));f.submit();"; + } + + /** + * Move modal when clicking on the open button. Trigger only once. + * @return string + */ public static function getMoveModalScript() { if (!PureModal::config()->move_modal_to_body) { return ''; } - return "document.getElementById('Form_ItemEditForm').appendChild(this.parentElement.querySelector('.pure-modal'));this.onclick=null;"; + $formId = PureModal::config()->edit_form_id; + return "document.getElementById('$formId').appendChild(this.parentElement.querySelector('.pure-modal'));this.onclick=null;"; } public function getAttributes()