Skip to content

Commit

Permalink
FormMacros: added support for <label n:name /> Checkbox label with ca…
Browse files Browse the repository at this point in the history
…ption rendering

Conflicts:
	tests/Forms.Latte/FormMacros.forms.phpt
  • Loading branch information
Koricz authored and dg committed Jun 17, 2015
1 parent ea7b7b8 commit 3ff9cc3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Bridges/FormsLatte/FormMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function macroNameEnd(MacroNode $node, PhpWriter $writer)
$node->content = $parts[1] . $parts[2] . '<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($_form, FALSE) ?>' . $parts[3];
} elseif ($tagName === 'label') {
if ($node->htmlNode->isEmpty) {
$node->content = $parts[1] . '<?php echo $_input->getLabel()->getHtml() ?>' . $parts[3];
$node->content = $parts[1] . "<?php echo \$_input->{method_exists(\$_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?>" . $parts[3];
}
} elseif ($tagName === 'button') {
if ($node->htmlNode->isEmpty) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Forms.Latte/FormMacros.forms.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $form->addText('username', 'Username:'); // must have just one textfield to gene
$form->addRadioList('sex', 'Sex:', array('m' => 'male', 'f' => 'female'));
$form->addSelect('select', NULL, array('m' => 'male', 'f' => 'female'));
$form->addTextArea('area', NULL)->setValue('one<two');
$form->addCheckbox('checkbox', NULL);
$form->addCheckbox('checkbox', 'Checkbox');
$form->addCheckboxList('checklist', 'CheckboxList:', array('m' => 'male', 'f' => 'female'));
$form->addSubmit('send', 'Sign in');
$form['my'] = new MyControl;
Expand Down
2 changes: 2 additions & 0 deletions tests/Forms.Latte/expected/FormMacros.forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
<label for="frm-checkbox"> <input type="checkbox" name="checkbox" id="frm-checkbox"> Label</label>
<label title=hello for="frm-checkbox"> <input type="checkbox" name="checkbox" id="frm-checkbox"> </label>
<label title=hello for="frm-checkbox"> <input type="checkbox" name="checkbox" id="frm-checkbox"> </label>
<label for="frm-checkbox">Checkbox</label>
<label title=hello for="frm-checkbox">Checkbox</label>


<label for="frm-checklist-m"> <input type="checkbox" name="checklist[]" id="frm-checklist-m" value="m"> male</label>
Expand Down
15 changes: 10 additions & 5 deletions tests/Forms.Latte/expected/FormMacros.forms.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_contro

<label<?php $_input = is_object($form['username']) ? $form['username'] : $_form[$form['username']]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>></label>
<label<?php $_input = is_object($form['username']) ? $form['username'] : $_form[$form['username']]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>
><?php echo $_input->getLabel()->getHtml() ?></label>
><?php echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>
<input<?php $_input = is_object($form['username']) ? $form['username'] : $_form[$form['username']]; echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>>

<?php if ($_label = $_form["my"]->getLabel()) echo $_label ; echo $_form["my"]->getControl() ?>
Expand All @@ -59,10 +59,10 @@ echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_contro
<?php $iterations++; } ?>
<label<?php $_input = $_form["sex"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>></label>
<label<?php $_input = $_form["sex"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>
><?php echo $_input->getLabel()->getHtml() ?></label>
><?php echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>
<label title="hello"<?php $_input = $_form["sex"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->addAttributes(array (
'title' => NULL,
))->attributes() ?>><?php echo $_input->getLabel()->getHtml() ?></label>
))->attributes() ?>><?php echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>


<?php if ($_label = $_form["checkbox"]->getLabelPart("")) echo $_label->startTag() ?>
Expand All @@ -74,6 +74,11 @@ echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_contro
<label title=hello<?php $_input = $_form["checkbox"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->addAttributes(array (
'title' => NULL,
))->attributes() ?>> <input<?php $_input = $_form["checkbox"]; echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>> </label>
<label<?php $_input = $_form["checkbox"]; echo $_input->getLabelPart("")->attributes() ?>
><?php echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>
<label title=hello<?php $_input = $_form["checkbox"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->addAttributes(array (
'title' => NULL,
))->attributes() ?>><?php echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>


<?php $iterations = 0; foreach ($form['checklist']->items as $key => $label) { ?>
Expand All @@ -87,10 +92,10 @@ echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_contro
<?php $iterations++; } ?>
<label<?php $_input = $_form["checklist"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>></label>
<label<?php $_input = $_form["checklist"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>
><?php echo $_input->getLabel()->getHtml() ?></label>
><?php echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>
<label title="hello"<?php $_input = $_form["checklist"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->addAttributes(array (
'title' => NULL,
))->attributes() ?>><?php echo $_input->getLabel()->getHtml() ?></label>
))->attributes() ?>><?php echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>


<?php if (1) { ?><form id="myForm" class="ajax"<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_control["myForm"], array (
Expand Down
2 changes: 2 additions & 0 deletions tests/Forms.Latte/templates/forms.latte
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
{label checkbox:} {input checkbox:} Label{/label}
<label n:name="checkbox:" title=hello> <input n:name="checkbox:"> </label>
<label n:name="checkbox" title=hello> <input n:name="checkbox"> </label>
<label n:name="checkbox:" />
<label n:name="checkbox" title=hello />


{* partial rendering of CheckboxList *}
Expand Down

0 comments on commit 3ff9cc3

Please sign in to comment.