Skip to content

Commit 9cb04d2

Browse files
committed
BaseControl::getHtmlId() autoprefixes standalone forms with form name (BC break)
1 parent 5754421 commit 9cb04d2

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/Forms/Controls/BaseControl.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,10 @@ public function getHtmlId()
337337
{
338338
if (!isset($this->control->id)) {
339339
$form = $this->getForm();
340-
$this->control->id = sprintf(self::$idMask, $this->lookupPath(), $form->getName());
340+
$prefix = $form instanceof Nette\Application\UI\Form || $form->getName() === null
341+
? ''
342+
: $form->getName() . '-';
343+
$this->control->id = sprintf(self::$idMask, $prefix . $this->lookupPath());
341344
}
342345
return $this->control->id;
343346
}

tests/Forms/Forms.idMask.phpt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,13 @@ test(function () {
4040

4141

4242
test(function () {
43-
Nette\Forms\Controls\BaseControl::$idMask = 'frm-%s-%s';
44-
4543
$form = new Form;
4644
$input = $form->addText('name');
47-
Assert::same('frm-name-', $input->getHtmlId());
45+
Assert::same('frm-name', $input->getHtmlId());
4846
});
4947

5048

5149
test(function () {
52-
Nette\Forms\Controls\BaseControl::$idMask = 'frm-%2$s-%1$s';
53-
5450
$form = new Form('signForm');
5551
$input = $form->addText('name');
5652
Assert::same('frm-signForm-name', $input->getHtmlId());

0 commit comments

Comments
 (0)