diff --git a/src/AbstractForm.php b/src/AbstractForm.php index c90e2fd..f32d33d 100644 --- a/src/AbstractForm.php +++ b/src/AbstractForm.php @@ -113,6 +113,13 @@ public function getTemplateFile(): string } + public function isPreventLeavingWhenDirty(): bool + { + $rc = new ReflectionClass($this); + return (bool) $rc->getAttributes(PreventLeavingWhenDirty::class); + } + + public function setTranslator(Translator $translator = null): void { $this->translator = $translator; @@ -278,6 +285,11 @@ public function render(): void $template->setParameters([ 'layout' => $this->layout, 'form' => $form, + + 'formOptions' => [ + 'data-check-dirty' => $this->isPreventLeavingWhenDirty(), + 'data-form-name' => $this->getName(), + ], ]); $template->render(); diff --git a/src/Attributes/PreventLeavingWhenDirty.php b/src/Attributes/PreventLeavingWhenDirty.php new file mode 100644 index 0000000..ecf571e --- /dev/null +++ b/src/Attributes/PreventLeavingWhenDirty.php @@ -0,0 +1,15 @@ +getName()}" n:class="card, 'card-'.$color, !isset($headColor) || $headColor != $color ? card-outline"> -