Skip to content

Commit 3a7690c

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: [DependencyInjection] Resolve aliases before removing abstract services + add tests Fix Dom Crawler select option with empty value Remove unnecessary option assignment remove unused variable [PropertyAccess] Fix regression
2 parents f7cbc7b + b1a52ae commit 3a7690c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Field/ChoiceFormField.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ private function buildOptionValue(\DOMElement $node)
263263
{
264264
$option = array();
265265

266-
$defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : 'on';
266+
$defaultDefaultValue = 'select' === $this->node->nodeName ? '' : 'on';
267+
$defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : $defaultDefaultValue;
267268
$option['value'] = $node->hasAttribute('value') ? $node->getAttribute('value') : $defaultValue;
268269
$option['disabled'] = $node->hasAttribute('disabled');
269270

Tests/Field/ChoiceFormFieldTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ public function testDisableValidation()
351351
$this->assertEquals(array('foobar'), $field->getValue(), '->disableValidation() allows to set a value which is not in the selected options.');
352352
}
353353

354+
public function testSelectWithEmptyValue()
355+
{
356+
$node = $this->createSelectNodeWithEmptyOption(array('' => true, 'Female' => false, 'Male' => false));
357+
$field = new ChoiceFormField($node);
358+
359+
$this->assertSame('', $field->getValue());
360+
}
361+
354362
protected function createSelectNode($options, $attributes = array(), $selectedAttrText = 'selected')
355363
{
356364
$document = new \DOMDocument();

0 commit comments

Comments
 (0)