Skip to content

Commit c2805ef

Browse files
Koriczdg
authored andcommitted
FormMacros: added support for <label n:name /> Checkbox label with caption rendering
1 parent c456e8d commit c2805ef

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

src/Bridges/FormsLatte/FormMacros.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function macroNameEnd(MacroNode $node, PhpWriter $writer)
189189
$node->content = $parts[1] . $parts[2] . '<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($_form, FALSE) ?>' . $parts[3];
190190
} elseif ($tagName === 'label') {
191191
if ($node->htmlNode->isEmpty) {
192-
$node->content = $parts[1] . '<?php echo $_input->getLabel()->getHtml() ?>' . $parts[3];
192+
$node->content = $parts[1] . "<?php echo \$_input->{method_exists(\$_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?>" . $parts[3];
193193
}
194194
} elseif ($tagName === 'button') {
195195
if ($node->htmlNode->isEmpty) {

tests/Forms.Latte/FormMacros.forms.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ $form->addText('username', 'Username:'); // must have just one textfield to gene
3232
$form->addRadioList('sex', 'Sex:', ['m' => 'male', 'f' => 'female']);
3333
$form->addSelect('select', NULL, ['m' => 'male', 'f' => 'female']);
3434
$form->addTextArea('area', NULL)->setValue('one<two');
35-
$form->addCheckbox('checkbox', NULL);
35+
$form->addCheckbox('checkbox', 'Checkbox');
3636
$form->addCheckboxList('checklist', 'CheckboxList:', ['m' => 'male', 'f' => 'female']);
3737
$form->addSubmit('send', 'Sign in');
3838
$form['my'] = new MyControl;

tests/Forms.Latte/expected/FormMacros.forms.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
<label for="frm-checkbox"> <input type="checkbox" name="checkbox" id="frm-checkbox"> Label</label>
7878
<label title=hello for="frm-checkbox"> <input type="checkbox" name="checkbox" id="frm-checkbox"> </label>
7979
<label title=hello for="frm-checkbox"> <input type="checkbox" name="checkbox" id="frm-checkbox"> </label>
80+
<label for="frm-checkbox">Checkbox</label>
81+
<label title=hello for="frm-checkbox">Checkbox</label>
8082

8183

8284
<label for="frm-checklist-m"> <input type="checkbox" name="checklist[]" id="frm-checklist-m" value="m"> male</label>

tests/Forms.Latte/expected/FormMacros.forms.phtml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_contro
3636

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

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

6767

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

7883

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

95100

96101
<?php if (1) { ?><form id="myForm" class="ajax"<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_control["myForm"], array (

tests/Forms.Latte/templates/forms.latte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
{label checkbox:} {input checkbox:} Label{/label}
4242
<label n:name="checkbox:" title=hello> <input n:name="checkbox:"> </label>
4343
<label n:name="checkbox" title=hello> <input n:name="checkbox"> </label>
44+
<label n:name="checkbox:" />
45+
<label n:name="checkbox" title=hello />
4446

4547

4648
{* partial rendering of CheckboxList *}

0 commit comments

Comments
 (0)