Changed the default value of checkbox and radio to match the HTML spec
When the checkbox or radio input does not have a value attribute, the HTML spec defines that the value should be 'on', not '1'.
This commit is contained in:
parent
2c6bdd82ce
commit
186b65ea5d
@ -4,6 +4,8 @@ CHANGELOG
|
||||
2.5.0
|
||||
-----
|
||||
|
||||
* [BC BREAK] The default value for checkbox and radio inputs without a value attribute have changed
|
||||
from '1' to 'on' to match the HTML specification.
|
||||
* [BC BREAK] The typehints on the `Link`, `Form` and `FormField` classes have been changed from
|
||||
`\DOMNode` to `DOMElement`. Using any other type of `DOMNode` was triggering fatal errors in previous
|
||||
versions. Code extending these classes will need to update the typehints when overwriting these methods.
|
||||
|
@ -267,7 +267,7 @@ class ChoiceFormField extends FormField
|
||||
{
|
||||
$option = array();
|
||||
|
||||
$defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : '1';
|
||||
$defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : 'on';
|
||||
$option['value'] = $node->hasAttribute('value') ? $node->getAttribute('value') : $defaultValue;
|
||||
$option['disabled'] = ($node->hasAttribute('disabled') && $node->getAttribute('disabled') == 'disabled');
|
||||
|
||||
|
@ -201,7 +201,7 @@ class ChoiceFormFieldTest extends FormFieldTestCase
|
||||
$field = new ChoiceFormField($node);
|
||||
|
||||
$this->assertTrue($field->hasValue(), '->hasValue() returns true when the checkbox is checked');
|
||||
$this->assertEquals('1', $field->getValue(), '->getValue() returns 1 if the checkbox is checked and has no value attribute');
|
||||
$this->assertEquals('on', $field->getValue(), '->getValue() returns 1 if the checkbox is checked and has no value attribute');
|
||||
|
||||
$node = $this->createNode('input', '', array('type' => 'checkbox', 'name' => 'name', 'checked' => 'checked', 'value' => 'foo'));
|
||||
$field = new ChoiceFormField($node);
|
||||
@ -240,7 +240,7 @@ class ChoiceFormFieldTest extends FormFieldTestCase
|
||||
$node = $this->createNode('input', '', array('type' => 'checkbox', 'name' => 'name'));
|
||||
$field = new ChoiceFormField($node);
|
||||
$field->tick();
|
||||
$this->assertEquals(1, $field->getValue(), '->tick() ticks checkboxes');
|
||||
$this->assertEquals('on', $field->getValue(), '->tick() ticks checkboxes');
|
||||
}
|
||||
|
||||
public function testUntick()
|
||||
@ -266,7 +266,7 @@ class ChoiceFormFieldTest extends FormFieldTestCase
|
||||
$node = $this->createNode('input', '', array('type' => 'checkbox', 'name' => 'name', 'checked' => 'checked'));
|
||||
$field = new ChoiceFormField($node);
|
||||
$field->select(true);
|
||||
$this->assertEquals(1, $field->getValue(), '->select() changes the value of the field');
|
||||
$this->assertEquals('on', $field->getValue(), '->select() changes the value of the field');
|
||||
$field->select(false);
|
||||
$this->assertNull($field->getValue(), '->select() changes the value of the field');
|
||||
|
||||
|
Reference in New Issue
Block a user