Skip to content

Commit

Permalink
Fix up tests for nested input/labels.
Browse files Browse the repository at this point in the history
Fixup nested inputs and add a new test showing how you can update the
templates to have non-nested inputs.
  • Loading branch information
markstory committed Oct 20, 2014
1 parent e9f4489 commit 5727368
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 60 deletions.
7 changes: 5 additions & 2 deletions src/View/Helper/FormHelper.php
Expand Up @@ -80,7 +80,7 @@ class FormHelper extends Helper {
'button' => '<button{{attrs}}>{{text}}</button>',
'checkbox' => '<input type="checkbox" name="{{name}}" value="{{value}}"{{attrs}}>',
'checkboxFormGroup' => '{{label}}',
'checkboxWrapper' => '<div class="checkbox">{{input}}{{label}}</div>',
'checkboxWrapper' => '<div class="checkbox">{{label}}</div>',
'dateWidget' => '{{year}}{{month}}{{day}}{{hour}}{{minute}}{{second}}{{meridian}}',
'error' => '<div class="error-message">{{content}}</div>',
'errorList' => '<ul>{{content}}</ul>',
Expand Down Expand Up @@ -923,10 +923,10 @@ public function input($fieldName, array $options = []) {
}

$label = $options['label'];
unset($options['label']);
$nestedInput = false;
if (in_array($options['type'], ['radio', 'checkbox'], true)) {
$nestedInput = true;
unset($options['label']);
}
$nestedInput = isset($options['nestedInput']) ? $options['nestedInput'] : $nestedInput;

Expand Down Expand Up @@ -1179,6 +1179,9 @@ protected function _getLabel($fieldName, $options) {
$label = $options['label'];
}

if ($label === false && isset($options['input'])) {
return $options['input'];
}
if ($label === false) {
return false;
}
Expand Down
34 changes: 34 additions & 0 deletions src/View/Widget/NestingLabel.php
@@ -0,0 +1,34 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\View\Widget;

use Cake\View\Widget\Label;

/**
* Form 'widget' for creating labels that contain their input.
*
* Generally this element is used by other widgets,
* and FormHelper itself.
*/
class NestingLabel extends Label {

/**
* The template to use.
*
* @var string
*/
protected $_labelTemplate = 'nestingLabel';

}

0 comments on commit 5727368

Please sign in to comment.