Skip to content

Commit

Permalink
Fix label element for attributes not matching their inputs.
Browse files Browse the repository at this point in the history
Radio elements would contain ModelModelFieldValue instead of
ModelFieldValue like they should. This was caused by the fix for #3936
and lack of tests for create() + radio().

Fixes #4071
  • Loading branch information
markstory committed Sep 17, 2013
1 parent aee71fa commit 5ec9b14
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -4097,6 +4097,27 @@ public function testRadioLabelArray() {
);
}

/**
* Test that label id's match the input element id's when radio is called after create().
*
* @return void
*/
public function testRadioWithCreate() {
$this->Form->create('Model');
$result = $this->Form->radio('recipient',
array('1' => '1', '2' => '2', '3' => '3'),
array('legend' => false, 'value' => '1')
);
$this->assertTextNotContains(
'<label for="ModelModelRecipient1">1</label>',
$result
);
$this->assertTextContains(
'<label for="ModelRecipient1">1</label>',
$result
);
}

/**
* testSelect method
*
Expand Down
4 changes: 3 additions & 1 deletion lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -1520,7 +1520,9 @@ public function radio($fieldName, $options = array(), $attributes = array()) {
);

if ($label) {
$optTitle = $this->label($tagName, $optTitle, is_array($label) ? $label : null);
$labelOpts = is_array($label) ? $label : array();
$labelOpts += array('for' => $tagName);
$optTitle = $this->label($tagName, $optTitle, $labelOpts);
}

if (is_array($between)) {
Expand Down

0 comments on commit 5ec9b14

Please sign in to comment.