diff --git a/js/forms/turbo_stream_event_element.js b/js/forms/turbo_stream_event_element.js index a20996752..28c7df052 100644 --- a/js/forms/turbo_stream_event_element.js +++ b/js/forms/turbo_stream_event_element.js @@ -10,7 +10,7 @@ class TurboStreamEvent extends HTMLElement { this.style.display = 'none'; - const event = new CustomEvent("itop:TurboStreamEvent", { + const event = new CustomEvent(`itop:TurboStreamEvent:${this.dataset.type}`, { detail: { id: this.getAttribute('id'), form_id: this.dataset.formId, diff --git a/js/layouts/dashboard/dashboard.js b/js/layouts/dashboard/dashboard.js index 9b43492b5..0613069bc 100644 --- a/js/layouts/dashboard/dashboard.js +++ b/js/layouts/dashboard/dashboard.js @@ -194,7 +194,7 @@ class IboDashboard extends HTMLElement { this.SetDashletForm(sFormData); // Listen to form submission event and cancellation - document.addEventListener('itop:TurboStreamEvent', me._ListenToDashletFormSubmission); + document.addEventListener('itop:TurboStreamEvent:Complete', me._ListenToDashletFormSubmission); document.querySelector('.ibo-dashlet-panel--form-container button[name="dashboard_cancel"]').addEventListener('click', me._ListenToDashletFormCancellation); }); } @@ -205,7 +205,7 @@ class IboDashboard extends HTMLElement { if(event.detail.id === oDashlet.sType + '-turbo-stream-event' && event.detail.valid === "1") { // Remove events - document.addEventListener('itop:TurboStreamEvent', this._ListenToDashletFormSubmission); + document.addEventListener('itop:TurboStreamEvent:Complete', this._ListenToDashletFormSubmission); document.querySelector('.ibo-dashlet-panel--form-container button[name="dashboard_cancel"]').removeEventListener('click', this._ListenToDashletFormCancellation); // Notify it all went well @@ -229,7 +229,7 @@ class IboDashboard extends HTMLElement { const oDashlet = this.querySelector('ibo-dashlet[data-edit-mode="edit"]'); const sDashletId = oDashlet.GetDashletId(); // Remove events - document.addEventListener('itop:TurboStreamEvent', this._ListenToDashletFormSubmission); + document.addEventListener('itop:TurboStreamEvent:Complete', this._ListenToDashletFormSubmission); document.querySelector('.ibo-dashlet-panel--form-container button[name="dashboard_cancel"]').removeEventListener('click', this._ListenToDashletFormCancellation); // Clean edit mode diff --git a/sources/Forms/Block/AbstractFormBlock.php b/sources/Forms/Block/AbstractFormBlock.php index 3b38fd590..4b6fb330b 100644 --- a/sources/Forms/Block/AbstractFormBlock.php +++ b/sources/Forms/Block/AbstractFormBlock.php @@ -88,6 +88,21 @@ abstract class AbstractFormBlock implements IFormBlock return $this->oParent; } + /** + * Get the root form. + * + * @return FormBlock|CollectionBlock|null + */ + public function GetRoot(): FormBlock|CollectionBlock|null + { + $oBlock = $this; + while (!$oBlock->IsRootBlock()) { + $oBlock = $oBlock->GetParent(); + } + + return $oBlock; + } + /** * Return true if this block is root. * diff --git a/sources/Forms/FormType/FormTypeHelper.php b/sources/Forms/FormType/FormTypeHelper.php index 6302b3396..1f79aaace 100644 --- a/sources/Forms/FormType/FormTypeHelper.php +++ b/sources/Forms/FormType/FormTypeHelper.php @@ -30,6 +30,7 @@ class FormTypeHelper if (is_null($oForm->getParent())) { return $oForm->getName(); } + return self::GetFormId($oForm->getParent()).'_'.$oForm->getName(); } @@ -52,7 +53,7 @@ class FormTypeHelper // Get the parent form $oParent = $oFormTurboTrigger->getParent(); - $sParentName = self::GetFormId($oParent); + $sParentName = self::GetFormId($oParent); // Get the block corresponding to the turbo trigger form $oBlockTurboTrigger = $oFormTurboTrigger->getConfig()->getOption('form_block'); @@ -72,7 +73,8 @@ class FormTypeHelper return [ 'blocks_to_redraw' => $aBlocksToRedraw, - 'current_block' => $oFormTurboTrigger->createView(), + 'current_block' => $oFormTurboTrigger->createView(), + 'root_form' => $oFormTurboTrigger->GetRoot()->createView(), ]; } diff --git a/templates/application/forms/turbo-ajax-update.html.twig b/templates/application/forms/turbo-ajax-update.html.twig index 69cf924af..d66d6d7d3 100644 --- a/templates/application/forms/turbo-ajax-update.html.twig +++ b/templates/application/forms/turbo-ajax-update.html.twig @@ -14,11 +14,12 @@ {% if current_block %} {% UITurboStream Replace { sTarget: "turbo_error_" ~ current_block.vars.id} %} {{ form_errors(current_block) }} + {% EndUITurboStream %} {% endif %} {% if current_form %} {% UITurboStream Replace { sTarget: current_form.vars.id} %} {{ form_widget(current_form) }} - + {% EndUITurboStream %} {% endif %}