Skip to content

Commit 5754421

Browse files
committed
BaseControl::getHtmlId() ensures that control is attached to the form (BC break)
1 parent 39b202c commit 5754421

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Forms/Controls/BaseControl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ public function setHtmlId($id)
336336
public function getHtmlId()
337337
{
338338
if (!isset($this->control->id)) {
339-
$form = $this->getForm(false);
340-
$this->control->id = sprintf(self::$idMask, $this->lookupPath(), $form ? $form->getName() : '');
339+
$form = $this->getForm();
340+
$this->control->id = sprintf(self::$idMask, $this->lookupPath(), $form->getName());
341341
}
342342
return $this->control->id;
343343
}

tests/Forms/Forms.idMask.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ require __DIR__ . '/../bootstrap.php';
1313
Assert::exception(function () {
1414
$input = new TextInput('name');
1515
$input->getHtmlId();
16-
}, Nette\InvalidStateException::class, "Component '' is not attached to ''.");
16+
}, Nette\InvalidStateException::class, "Component '' is not attached to 'Nette\\Forms\\Form'.");
1717

1818

19-
test(function () {
19+
Assert::exception(function () {
2020
$container = new Nette\Forms\Container;
2121
$container->setParent(null, 'second');
2222
$input = $container->addText('name');
23-
Assert::same('frm-name', $input->getHtmlId());
24-
});
23+
$input->getHtmlId();
24+
}, Nette\InvalidStateException::class, "Component 'name' is not attached to 'Nette\\Forms\\Form'.");
2525

2626

2727
test(function () {

0 commit comments

Comments
 (0)