Skip to content
Permalink
Browse files

Allow configuring grouped input types.

Closes #11850.
  • Loading branch information...
ADmad committed Apr 2, 2018
1 parent 7037d74 commit aae9471498fdca74b27e4f502a15a0c198becff3
Showing with 29 additions and 2 deletions.
  1. +13 −2 src/View/Helper/FormHelper.php
  2. +16 −0 tests/TestCase/View/Helper/FormHelperTest.php
@@ -253,6 +253,13 @@ class FormHelper extends Helper
*/
protected $_valueSources = ['context'];
/**
* Grouped input types.
*
* @var array
*/
protected $_groupedInputTypes = ['radio', 'multicheckbox', 'date', 'time', 'datetime'];
/**
* Construct the widgets and binds the default context providers
*
@@ -280,6 +287,11 @@ public function __construct(View $View, array $config = [])
unset($config['widgets']);
}
if (isset($config['groupedInputTypes'])) {
$this->_groupedInputTypes = $config['groupedInputTypes'];
unset($config['groupedInputTypes']);
}
parent::__construct($View, $config);
if (!$locator) {
@@ -1550,8 +1562,7 @@ protected function _inputLabel($fieldName, $label, $options)
}
$labelAttributes['for'] = $options['id'];
$groupTypes = ['radio', 'multicheckbox', 'date', 'time', 'datetime'];
if (in_array($options['type'], $groupTypes, true)) {
if (in_array($options['type'], $this->_groupedInputTypes, true)) {
$labelAttributes['for'] = false;
}
if ($options['nestedInput']) {
@@ -259,6 +259,22 @@ public function testSetAndGetWidgetLocator()
$this->assertSame($locator, $helper->getWidgetLocator());
}
/**
* Test overridding grouped input types which controls generation of "for"
* attribute of labels.
*
* @return void
*/
public function testConstructWithGroupedInputTypes()
{
$helper = new FormHelper($this->View, [
'groupedInputTypes' => ['radio'],
]);
$result = $helper->control('when', ['type' => 'datetime']);
$this->assertContains('<label for="when">When</label>', $result);
}
/**
* Test registering a new widget class and rendering it.
*

0 comments on commit aae9471

Please sign in to comment.
You can’t perform that action at this time.