diff --git a/src/Bridges/FormsLatte/FormMacros.php b/src/Bridges/FormsLatte/FormMacros.php index 789b7bc61..20186dd59 100644 --- a/src/Bridges/FormsLatte/FormMacros.php +++ b/src/Bridges/FormsLatte/FormMacros.php @@ -163,6 +163,11 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer) $tagName = strtolower($node->htmlNode->name); $node->empty = $tagName === 'input'; + $definedHtmlAttributes = array_keys($node->htmlNode->attrs); + if (isset($node->htmlNode->macroAttrs['class'])) { + $definedHtmlAttributes[] = 'class'; + } + if ($tagName === 'form') { $node->openingCode = $writer->write( 'global->formsStack[] = ' @@ -172,17 +177,17 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer) ); return $writer->write( 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), %0.var, false)', - array_fill_keys(array_keys($node->htmlNode->attrs), null) + array_fill_keys($definedHtmlAttributes, null) ); } else { $method = $tagName === 'label' ? 'getLabel' : 'getControl'; return $writer->write( '$_input = ' . ($name[0] === '$' ? 'is_object(%0.word) ? %0.word : ' : '') . 'end($this->global->formsStack)[%0.word]; echo $_input->%1.raw' - . ($node->htmlNode->attrs ? '->addAttributes(%2.var)' : '') . '->attributes()', + . ($definedHtmlAttributes ? '->addAttributes(%2.var)' : '') . '->attributes()', $name, $method . 'Part(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')', - array_fill_keys(array_keys($node->htmlNode->attrs), null) + array_fill_keys($definedHtmlAttributes, null) ); } } diff --git a/tests/Forms.Latte/FormMacros.forms.phpt b/tests/Forms.Latte/FormMacros.forms.phpt index a7184d4df..c696ffde2 100644 --- a/tests/Forms.Latte/FormMacros.forms.phpt +++ b/tests/Forms.Latte/FormMacros.forms.phpt @@ -28,8 +28,10 @@ class MyControl extends Nette\Forms\Controls\BaseControl $form = new Form; +$form->getElementPrototype()->addClass('form-class'); $form->addHidden('id'); $form->addText('username', 'Username:'); // must have just one textfield to generate IE fix +$form['username']->getControlPrototype()->addClass('control-class'); $form->addRadioList('sex', 'Sex:', ['m' => 'male', 'f' => 'female']); $form->addSelect('select', null, ['m' => 'male', 'f' => 'female']); $form->addTextArea('area', null)->setValue('one +
@@ -9,13 +9,13 @@ - + error error
- + error @@ -52,7 +52,7 @@ - + @@ -60,11 +60,11 @@ - +
-
+ @@ -91,13 +91,19 @@ - +
-
- + + + +
+ + +
+
diff --git a/tests/Forms.Latte/expected/FormMacros.forms.phtml b/tests/Forms.Latte/expected/FormMacros.forms.phtml index 7f59824b9..46737a98a 100644 --- a/tests/Forms.Latte/expected/FormMacros.forms.phtml +++ b/tests/Forms.Latte/expected/FormMacros.forms.phtml @@ -202,6 +202,24 @@ ?> +global->formsStack[] = $this->global->uiControl["myForm"]; + ?>global->formsStack), array ( + 'class' => NULL, + ), false) ?>> + global->formsStack)["username"]; + echo $_input->getControlPart()->addAttributes(array ( + 'class' => NULL, + ))->attributes(); + if ($_tmp = array_filter(['nclass'])) echo ' class="', LR\Filters::escapeHtmlAttr(implode(" ", array_unique($_tmp))), '"' ?>> +global->formsStack), false); +?> + + global->formsStack[] = is_object($this->global->uiControl['myForm']) ? $this->global->uiControl['myForm'] : $this->global->uiControl[$this->global->uiControl['myForm']]; ?>getControlPart()->attributes() ?>>getControl()->getHtml() ?> -