Skip to content

Commit

Permalink
CheckboxList: removed compatibility workaround for label vs item labe…
Browse files Browse the repository at this point in the history
…l (BC break)
  • Loading branch information
dg committed Jan 30, 2017
1 parent 62ef303 commit 48efa1d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/Forms/Controls/CheckboxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct($label = NULL, array $items = NULL)
$this->control->type = 'checkbox';
$this->container = Html::el();
$this->separator = Html::el('br');
// $this->itemLabel = Html::el('label'); back compatiblity
$this->itemLabel = Html::el('label');
$this->setOption('type', 'checkbox');
}

Expand All @@ -65,7 +65,7 @@ public function getControl(): Html
'required' => NULL,
'data-nette-rules:' => [key($items) => $input->attrs['data-nette-rules']],
]),
$this->itemLabel ? $this->itemLabel->attrs : $this->label->attrs,
$this->itemLabel->attrs,
$this->separator
)
);
Expand Down Expand Up @@ -97,7 +97,7 @@ public function getControlPart($key = NULL): Html

public function getLabelPart($key = NULL): Html
{
$itemLabel = $this->itemLabel ? clone $this->itemLabel : clone $this->label;
$itemLabel = clone $this->itemLabel;
return func_num_args()
? $itemLabel->setText($this->translate($this->items[$key]))->for($this->getHtmlId() . '-' . $key)
: $this->getLabel();
Expand Down Expand Up @@ -127,7 +127,7 @@ public function getContainerPrototype(): Html
*/
public function getItemLabelPrototype(): Html
{
return $this->itemLabel ?: $this->itemLabel = Html::el('label');
return $this->itemLabel;
}

}
13 changes: 0 additions & 13 deletions tests/Forms/Controls.CheckboxList.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,3 @@ test(function () { // item label prototype
Assert::same('<label class="foo" for="frm-list-a">b</label>', (string) $input->getLabelPart('a'));
Assert::same('<label class="foo"><input type="checkbox" name="list[]" value="a">b</label>', (string) $input->getControl());
});


test(function () { // item label prototype (back compatiblity)
$form = new Form;
$input = $form->addCheckboxList('list', NULL, [
'a' => 'b',
]);
$input->getLabelPrototype()->class('foo');

Assert::same('<label class="foo"></label>', (string) $input->getLabel());
Assert::same('<label class="foo" for="frm-list-a">b</label>', (string) $input->getLabelPart('a'));
Assert::same('<label class="foo"><input type="checkbox" name="list[]" value="a">b</label>', (string) $input->getControl());
});

0 comments on commit 48efa1d

Please sign in to comment.