diff --git a/src/Bridges/FormsLatte/FormMacros.php b/src/Bridges/FormsLatte/FormMacros.php index 736ca3349..6db574965 100644 --- a/src/Bridges/FormsLatte/FormMacros.php +++ b/src/Bridges/FormsLatte/FormMacros.php @@ -67,11 +67,13 @@ public function macroForm(MacroNode $node, PhpWriter $writer) $node->replaced = true; $node->tokenizer->reset(); return $writer->write( - 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $this->global->formsStack[] = ' + '$form = $this->global->formsStack[] = ' . ($name[0] === '$' ? 'is_object($ʟ_tmp = %node.word) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp]' : '$this->global->uiControl[%node.word]') - . ', %node.array)' + . ';' + . 'Nette\Bridges\FormsLatte\Runtime::initializeForm($form);' + . 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, %node.array)' . " /* line $node->startLine */;" ); } @@ -226,7 +228,8 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer) . ($name[0] === '$' ? 'is_object($ʟ_tmp = %0.word) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp]' : '$this->global->uiControl[%0.word]') - . " /* line $node->startLine */; ?>", + . " /* line $node->startLine */;" + . 'Nette\Bridges\FormsLatte\Runtime::initializeForm($form); ?>', $name ); return $writer->write( diff --git a/src/Bridges/FormsLatte/Nodes/FormNNameNode.php b/src/Bridges/FormsLatte/Nodes/FormNNameNode.php index 2de161e4a..75119298e 100644 --- a/src/Bridges/FormsLatte/Nodes/FormNNameNode.php +++ b/src/Bridges/FormsLatte/Nodes/FormNNameNode.php @@ -47,6 +47,7 @@ public function print(PrintContext $context): string ? '$this->global->uiControl[%node]' : 'is_object($ʟ_tmp = %node) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp]') . ' %line;' + . 'Nette\Bridges\FormsLatte\Runtime::initializeForm($form);' . '%node ' . 'array_pop($this->global->formsStack);', $this->name, diff --git a/src/Bridges/FormsLatte/Nodes/FormNode.php b/src/Bridges/FormsLatte/Nodes/FormNode.php index c2902d78d..2146a18a3 100644 --- a/src/Bridges/FormsLatte/Nodes/FormNode.php +++ b/src/Bridges/FormsLatte/Nodes/FormNode.php @@ -66,6 +66,7 @@ public function print(PrintContext $context): string ? '$this->global->uiControl[%node]' : 'is_object($ʟ_tmp = %node) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp]') . ' %line;' + . 'Nette\Bridges\FormsLatte\Runtime::initializeForm($form);' . ($this->print ? 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, %node) %1.line;' : '') diff --git a/src/Bridges/FormsLatte/Runtime.php b/src/Bridges/FormsLatte/Runtime.php index 1e1eb3605..4eee9413f 100644 --- a/src/Bridges/FormsLatte/Runtime.php +++ b/src/Bridges/FormsLatte/Runtime.php @@ -23,16 +23,20 @@ class Runtime { use Nette\StaticClass; - /** - * Renders form begin. - */ - public static function renderFormBegin(Form $form, array $attrs, bool $withTags = true): string + public static function initializeForm(Form $form): void { $form->fireRenderEvents(); foreach ($form->getControls() as $control) { $control->setOption('rendered', false); } + } + + /** + * Renders form begin. + */ + public static function renderFormBegin(Form $form, array $attrs, bool $withTags = true): string + { $el = $form->getElementPrototype(); $el->action = (string) $el->action; $el = clone $el; diff --git a/tests/Forms.Latte2/expected/FormMacros.button.php b/tests/Forms.Latte2/expected/FormMacros.button.php index eee0f8d0f..984e031a8 100644 --- a/tests/Forms.Latte2/expected/FormMacros.button.php +++ b/tests/Forms.Latte2/expected/FormMacros.button.php @@ -1,6 +1,7 @@ global->formsStack[] = $this->global->uiControl["myForm"] /* line 1 */; + Nette\Bridges\FormsLatte\Runtime::initializeForm($form); echo '