Skip to content

Commit

Permalink
Merge pull request #6221 from cakephp/form-group-by-types
Browse files Browse the repository at this point in the history
Support form groups templates by type
  • Loading branch information
markstory committed Mar 31, 2015
2 parents 5e72390 + c946d18 commit b299e2a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -1053,7 +1053,10 @@ public function input($fieldName, array $options = [])
*/
protected function _groupTemplate($options)
{
$groupTemplate = $options['options']['type'] === 'checkbox' ? 'checkboxFormGroup' : 'formGroup';
$groupTemplate = $options['options']['type'] . 'FormGroup';
if (!$this->templater()->get($groupTemplate)) {
$groupTemplate = 'formGroup';
}
return $this->templater()->format($groupTemplate, [
'input' => $options['input'],
'label' => $options['label'],
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -6967,6 +6967,26 @@ public function testInputContainerTemplates()
$this->assertContains('<div class="dt">', $result);
}

/**
* Test that *Container templates are used by input.
*
* @return void
*/
public function testFormGroupTemplates()
{
$this->Form->templates([
'radioFormGroup' => '<div class="radio">{{label}}{{input}}</div>',
]);

$this->Form->create($this->article);

$result = $this->Form->input('accept', [
'type' => 'radio',
'options' => ['Y', 'N']
]);
$this->assertContains('<div class="radio">', $result);
}

/**
* Test resetting templates.
*
Expand Down

0 comments on commit b299e2a

Please sign in to comment.