Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cb5fdaf

Browse filesBrowse files
bug #59399 [DomCrawler] Make ChoiceFormField::isDisabled return true for unchecked disabled checkboxes (MatTheCat)
This PR was merged into the 6.4 branch. Discussion ---------- [DomCrawler] Make `ChoiceFormField::isDisabled` return `true` for unchecked disabled checkboxes | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #8348 | License | MIT `ChoiceFormField::isDisabled`’s PHPDoc reads > Check if the current selected option is disabled. But a checkbox really embeds two options: either you check it, or not; which means it always has a selected option. Then, if a checkbox is disabled, these two options are too. So, `ChoiceFormField::isDisabled` should return `true` for disabled checkboxes, checked or not. This also matches what you intuitively would expect from this method. Commits ------- 9807ce6 [DomCrawler] Make `ChoiceFormField::isDisabled` return `true` for unchecked disabled checkboxes
2 parents 942aab8 + 9807ce6 commit cb5fdaf
Copy full SHA for cb5fdaf

File tree

Expand file treeCollapse file tree

2 files changed

+15
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-0
lines changed

‎src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public function hasValue(): bool
4545
*/
4646
public function isDisabled(): bool
4747
{
48+
if ('checkbox' === $this->type) {
49+
return parent::isDisabled();
50+
}
51+
4852
if (parent::isDisabled() && 'select' === $this->type) {
4953
return true;
5054
}

‎src/Symfony/Component/DomCrawler/Tests/Field/ChoiceFormFieldTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Tests/Field/ChoiceFormFieldTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,17 @@ public function testCheckboxWithEmptyBooleanAttribute()
272272
$this->assertEquals('foo', $field->getValue());
273273
}
274274

275+
public function testCheckboxIsDisabled()
276+
{
277+
$node = $this->createNode('input', '', ['type' => 'checkbox', 'name' => 'name', 'disabled' => '']);
278+
$field = new ChoiceFormField($node);
279+
280+
$this->assertTrue($field->isDisabled(), '->isDisabled() returns true when the checkbox is disabled, even if it is not checked');
281+
282+
$field->tick();
283+
$this->assertTrue($field->isDisabled(), '->isDisabled() returns true when the checkbox is disabled, even if it is checked');
284+
}
285+
275286
public function testTick()
276287
{
277288
$node = $this->createSelectNode(['foo' => false, 'bar' => false]);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.