Skip to content

Commit

Permalink
CheckboxList, RadioList: fixed rendering of <label n:name>
Browse files Browse the repository at this point in the history
Conflicts:
	tests/Forms.Latte/FormMacros.forms.phpt
  • Loading branch information
dg committed Jun 17, 2015
1 parent a1e3965 commit ea7b7b8
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/Forms/Controls/CheckboxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ public function getControlPart($key)
/**
* @return Html
*/
public function getLabelPart($key)
public function getLabelPart($key = NULL)
{
return parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key);
return func_num_args()
? parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key)
: $this->getLabel();
}

}
6 changes: 4 additions & 2 deletions src/Forms/Controls/RadioList.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ public function getControlPart($key)
/**
* @return Html
*/
public function getLabelPart($key)
public function getLabelPart($key = NULL)
{
return parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key);
return func_num_args()
? parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key)
: $this->getLabel();
}

}
2 changes: 1 addition & 1 deletion tests/Forms.Latte/FormMacros.forms.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $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->addCheckboxList('checklist', NULL, array('m' => 'male', 'f' => 'female'));
$form->addCheckboxList('checklist', 'CheckboxList:', array('m' => 'male', 'f' => 'female'));
$form->addSubmit('send', 'Sign in');
$form['my'] = new MyControl;

Expand Down
6 changes: 6 additions & 0 deletions tests/Forms.Latte/expected/FormMacros.forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<label title=hello for="frm-sex-m"> <input type="radio" name="sex" id="frm-sex-m" value="m"> </label>
<label for="frm-sex-f"> <input type="radio" name="sex" id="frm-sex-f" value="f"> female</label>
<label title=hello for="frm-sex-f"> <input type="radio" name="sex" id="frm-sex-f" value="f"> </label>
<label></label>
<label>Sex:</label>
<label title="hello">Sex:</label>


<label for="frm-checkbox"> <input type="checkbox" name="checkbox" id="frm-checkbox"> Label</label>
Expand All @@ -80,6 +83,9 @@
<label for="frm-checklist-m"> <input title=hello type="checkbox" name="checklist[]" id="frm-checklist-m" value="m"> </label>
<label for="frm-checklist-f"> <input type="checkbox" name="checklist[]" id="frm-checklist-f" value="f"> female</label>
<label for="frm-checklist-f"> <input title=hello type="checkbox" name="checklist[]" id="frm-checklist-f" value="f"> </label>
<label></label>
<label>CheckboxList:</label>
<label title="hello">CheckboxList:</label>


<form id="myForm" class="ajax" action="" method="post">
Expand Down
12 changes: 12 additions & 0 deletions tests/Forms.Latte/expected/FormMacros.forms.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_contro
'title' => NULL,
))->attributes() ?>> <input<?php $_input = $_form["sex"]; echo $_input->getControlPart($key)->attributes() ?>> </label>
<?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>
<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>


<?php if ($_label = $_form["checkbox"]->getLabelPart("")) echo $_label->startTag() ?>
Expand All @@ -79,6 +85,12 @@ echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_contro
'title' => NULL,
))->attributes() ?>> </label>
<?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>
<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>


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


{* partial rendering of Checkbox *}
Expand All @@ -45,6 +48,9 @@
{label checklist:$key} {input checklist:$key} {$label}{/label}
<label n:name="checklist:$key"> <input n:name="checklist:$key" title=hello> </label>
{/foreach}
<label n:name="checklist"></label>
<label n:name="checklist" />
<label n:name="checklist" title="hello" />


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

0 comments on commit ea7b7b8

Please sign in to comment.