-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BaseControl: added ability to multiple forms with different HTML ID [C…
…loses #188] Solution: set Nette\Forms\Controls\BaseControl::$idMask = 'frm-%2$s-%1$s';
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
use Nette\Forms\Controls\TextInput; | ||
use Nette\Forms\Form; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
Assert::exception(function () { | ||
$input = new TextInput('name'); | ||
$input->getHtmlId(); | ||
}, Nette\InvalidStateException::class, "Component '' is not attached to ''."); | ||
|
||
|
||
test(function () { | ||
$container = new Nette\Forms\Container; | ||
$container->setParent(null, 'second'); | ||
$input = $container->addText('name'); | ||
Assert::same('frm-name', $input->getHtmlId()); | ||
}); | ||
|
||
|
||
test(function () { | ||
$form = new Form; | ||
$container = $form->addContainer('second'); | ||
$input = $container->addText('name'); | ||
Assert::same('frm-second-name', $input->getHtmlId()); | ||
}); | ||
|
||
|
||
test(function () { | ||
$form = new Form; | ||
$input = $form->addText('name'); | ||
Assert::same('frm-name', $input->getHtmlId()); | ||
}); | ||
|
||
|
||
test(function () { | ||
Nette\Forms\Controls\BaseControl::$idMask = 'frm-%s-%s'; | ||
|
||
$form = new Form; | ||
$input = $form->addText('name'); | ||
Assert::same('frm-name-', $input->getHtmlId()); | ||
}); | ||
|
||
|
||
test(function () { | ||
Nette\Forms\Controls\BaseControl::$idMask = 'frm-%2$s-%1$s'; | ||
|
||
$form = new Form('signForm'); | ||
$input = $form->addText('name'); | ||
Assert::same('frm-signForm-name', $input->getHtmlId()); | ||
}); |
0fa9e5e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add this to docs?
Edit: Should I prepare PR?
0fa9e5e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great :)