Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Bridges/FormsLatte/FormMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function install(Latte\Compiler $compiler)
{
$me = new static($compiler);
$me->addMacro('form', array($me, 'macroForm'), 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($_form)');
$me->addMacro('formContainer', array($me, 'macroFormContainer'), '$_form = array_pop($_formStack)');
$me->addMacro('formContainer', array($me, 'macroFormContainer'), '$formContainer = $_form = array_pop($_formStack)');
$me->addMacro('label', array($me, 'macroLabel'), array($me, 'macroLabelEnd'));
$me->addMacro('input', array($me, 'macroInput'), NULL, array($me, 'macroInputAttr'));
$me->addMacro('name', array($me, 'macroName'), array($me, 'macroNameEnd'), array($me, 'macroNameAttr'));
Expand Down
7 changes: 7 additions & 0 deletions tests/Forms.Latte/FormMacros.formContainer.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ $cont2->addCheckbox('input6', 'Input 6');

$cont1->addText('input7', 'Input 7');

$contItems = $form->addContainer('items');
$items = array(1, 3);
foreach($items as $item) {
$contItem = $contItems->addContainer($item);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after foreach should be space

$contItem->addText('input', 'Input');
}

$form->addSubmit('input8', 'Input 8');


Expand Down
7 changes: 7 additions & 0 deletions tests/Forms.Latte/expected/FormMacros.formContainer.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
<th><label for="frm-cont1-input7">Input 7</label></th>
<td><input type="text" name="cont1[input7]" id="frm-cont1-input7"></td>
</tr>
<tr>
<th>Items</th>
<td>
<input type="text" name="items[1][input]" id="frm-items-1-input">
<input type="text" name="items[3][input]" id="frm-items-3-input">
</td>
</tr>
<tr>
<th></th>
<td><input type="submit" name="input8" value="Input 8"></td>
Expand Down
14 changes: 12 additions & 2 deletions tests/Forms.Latte/expected/FormMacros.formContainer.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@ echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_contro
<?php $iterations = 0; foreach ($formContainer->controls AS $name => $field) { ?>
<li><?php $_input = is_object($field) ? $field : $_form[$field]; echo $_input->getControl() ?></li>
<?php $iterations++; } ?> </ol>
<?php $_form = array_pop($_formStack) ?>
<?php $formContainer = $_form = array_pop($_formStack) ?>
</td>
</tr>
<tr>
<th><?php if ($_label = $_form["input7"]->getLabel()) echo $_label ?></th>
<td><?php echo $_form["input7"]->getControl() ?></td>
</tr>
<?php $_form = array_pop($_formStack) ?>
<?php $formContainer = $_form = array_pop($_formStack) ;$_formStack[] = $_form; $formContainer = $_form = $_form["items"] ?>
<tr>
<th>Items</th>
<td>
<?php $items = array(1, 2, 3) ;$iterations = 0; foreach ($items as $item) { if (!isset($formContainer[$item])) continue ;$_formStack[] = $_form; $formContainer = $_form = is_object($item) ? $item : $_form[$item] ?>
<?php echo $_form["input"]->getControl() ?>

<?php $formContainer = $_form = array_pop($_formStack) ;$iterations++; } ?>
</td>
</tr>
<?php $formContainer = $_form = array_pop($_formStack) ?>
<tr>
<th><?php if ($_label = $_form["input8"]->getLabel()) echo $_label ?></th>
<td><?php echo $_form["input8"]->getControl() ?></td>
Expand Down
14 changes: 14 additions & 0 deletions tests/Forms.Latte/templates/forms.formContainer.latte
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@
<td>{input input7}</td>
</tr>
{/formContainer}
{formContainer items}
<tr>
<th>Items</th>
<td>
{var $items = array(1, 2, 3)}
{foreach $items as $item}
{continueIf !isset($formContainer[$item])}
{formContainer $item}
{input input}
{/formContainer}
{/foreach}
</td>
</tr>
{/formContainer}
<tr>
<th>{label input8 /}</th>
<td>{input input8}</td>
Expand Down