Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Radio inputs don't check if bound to subdocument #815

Merged
merged 1 commit into from

2 participants

Eric Cholis Nate Abele
Eric Cholis

Copying the behavior of Form->checkbox(), adding support for binding subdocuments to radio inputs.

Updating #668 against current dev branch, and adding tests.

Test case is copied from FormTest->testCheckboxGeneration(), line 425

Nate Abele nateabele merged commit 6092755 into from
Eric Cholis ericcholis deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
3  template/helper/Form.php
View
@@ -681,12 +681,13 @@ public function radio($name, array $options = array()) {
$defaults = array('value' => '1');
$options += $defaults;
$default = $options['value'];
+ $key = $name;
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
list($scope, $options) = $this->_options($defaults, $options);
if (!isset($options['checked'])) {
- $options['checked'] = ($this->binding($name)->data == $default);
+ $options['checked'] = ($this->binding($key)->data == $default);
}
$options['value'] = $scope['value'];
18 tests/cases/template/helper/FormTest.php
View
@@ -568,6 +568,24 @@ public function testRadioGeneration() {
'type' => 'radio', 'value' => '1', 'name' => 'foo', 'id' => 'MockFormPostFoo'
))
));
+
+ $document = new Document(array(
+ 'model' => $this->_model,
+ 'data' => array(
+ 'subdocument' => array(
+ 'foo' => true
+ )
+ )
+ ));
+ $this->form->create($document);
+
+ $result = $this->form->radio('subdocument.foo');
+ $this->assertTags($result, array(
+ array('input' => array(
+ 'type' => 'radio', 'value' => '1', 'name' => 'subdocument[foo]', 'id' => 'MockFormPostSubdocumentFoo',
+ 'checked' => 'checked'
+ ))
+ ));
}
public function testCustomRadio() {
Something went wrong with that request. Please try again.