Skip to content

Commit c456e8d

Browse files
committed
CheckboxList, RadioList: fixed rendering of <label n:name>
1 parent a1aab9e commit c456e8d

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

src/Forms/Controls/CheckboxList.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ public function getControlPart($key)
9696
/**
9797
* @return Html
9898
*/
99-
public function getLabelPart($key)
99+
public function getLabelPart($key = NULL)
100100
{
101-
return parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key);
101+
return func_num_args()
102+
? parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key)
103+
: $this->getLabel();
102104
}
103105

104106
}

src/Forms/Controls/RadioList.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ public function getControlPart($key)
149149
/**
150150
* @return Html
151151
*/
152-
public function getLabelPart($key)
152+
public function getLabelPart($key = NULL)
153153
{
154-
return parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key);
154+
return func_num_args()
155+
? parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key)
156+
: $this->getLabel();
155157
}
156158

157159
}

tests/Forms.Latte/FormMacros.forms.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ $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');
3535
$form->addCheckbox('checkbox', NULL);
36-
$form->addCheckboxList('checklist', NULL, ['m' => 'male', 'f' => 'female']);
36+
$form->addCheckboxList('checklist', 'CheckboxList:', ['m' => 'male', 'f' => 'female']);
3737
$form->addSubmit('send', 'Sign in');
3838
$form['my'] = new MyControl;
3939

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
<label title=hello for="frm-sex-m"> <input type="radio" name="sex" id="frm-sex-m" value="m"> </label>
7070
<label for="frm-sex-f"> <input type="radio" name="sex" id="frm-sex-f" value="f"> female</label>
7171
<label title=hello for="frm-sex-f"> <input type="radio" name="sex" id="frm-sex-f" value="f"> </label>
72+
<label></label>
73+
<label>Sex:</label>
74+
<label title="hello">Sex:</label>
7275

7376

7477
<label for="frm-checkbox"> <input type="checkbox" name="checkbox" id="frm-checkbox"> Label</label>
@@ -80,6 +83,9 @@
8083
<label for="frm-checklist-m"> <input title=hello type="checkbox" name="checklist[]" id="frm-checklist-m" value="m"> </label>
8184
<label for="frm-checklist-f"> <input type="checkbox" name="checklist[]" id="frm-checklist-f" value="f"> female</label>
8285
<label for="frm-checklist-f"> <input title=hello type="checkbox" name="checklist[]" id="frm-checklist-f" value="f"> </label>
86+
<label></label>
87+
<label>CheckboxList:</label>
88+
<label title="hello">CheckboxList:</label>
8389

8490

8591
<form id="myForm" class="ajax" action="" method="post">

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_contro
5757
'title' => NULL,
5858
))->attributes() ?>> <input<?php $_input = $_form["sex"]; echo $_input->getControlPart($key)->attributes() ?>> </label>
5959
<?php $iterations++; } ?>
60+
<label<?php $_input = $_form["sex"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>></label>
61+
<label<?php $_input = $_form["sex"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>
62+
><?php echo $_input->getLabel()->getHtml() ?></label>
63+
<label title="hello"<?php $_input = $_form["sex"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->addAttributes(array (
64+
'title' => NULL,
65+
))->attributes() ?>><?php echo $_input->getLabel()->getHtml() ?></label>
6066

6167

6268
<?php if ($_label = $_form["checkbox"]->getLabelPart("")) echo $_label->startTag() ?>
@@ -79,6 +85,12 @@ echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_contro
7985
'title' => NULL,
8086
))->attributes() ?>> </label>
8187
<?php $iterations++; } ?>
88+
<label<?php $_input = $_form["checklist"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>></label>
89+
<label<?php $_input = $_form["checklist"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>
90+
><?php echo $_input->getLabel()->getHtml() ?></label>
91+
<label title="hello"<?php $_input = $_form["checklist"]; echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->addAttributes(array (
92+
'title' => NULL,
93+
))->attributes() ?>><?php echo $_input->getLabel()->getHtml() ?></label>
8294

8395

8496
<?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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
{label sex:$key} {input sex:$key} {$label}{/label}
3333
<label n:name="sex:$key" title=hello> <input n:name="sex:$key"> </label>
3434
{/foreach}
35+
<label n:name="sex"></label>
36+
<label n:name="sex" />
37+
<label n:name="sex" title="hello" />
3538

3639

3740
{* partial rendering of Checkbox *}
@@ -45,6 +48,9 @@
4548
{label checklist:$key} {input checklist:$key} {$label}{/label}
4649
<label n:name="checklist:$key"> <input n:name="checklist:$key" title=hello> </label>
4750
{/foreach}
51+
<label n:name="checklist"></label>
52+
<label n:name="checklist" />
53+
<label n:name="checklist" title="hello" />
4854

4955

5056
<form n:name="myForm" id="myForm" class="ajax" n:if=1>

0 commit comments

Comments
 (0)