Permalink
Browse files

The $fields parameter should only handle customizing fields.

The fields parameter should not duplicate the functionality found in the
blacklist parameter. Instead it should only allow customizing the
generated fields.
  • Loading branch information...
1 parent 45fe7eb commit 6fa3dfdcc9018bcad3d21246a49262f77956214c @markstory markstory committed Mar 5, 2014
Showing with 43 additions and 11 deletions.
  1. +19 −10 src/View/Helper/FormHelper.php
  2. +24 −1 tests/TestCase/View/Helper/FormHelperTest.php
@@ -712,17 +712,26 @@ protected function _domId($value) {
*
* You can customize individual inputs through `$fields`.
* {{{
- * $this->Form->inputs(array(
- * 'name' => array('label' => 'custom label')
- * ));
+ * $this->Form->inputs([
+ * 'name' => ['label' => 'custom label']
+ * ]);
* }}}
*
+ * You can exclude fields using the `$blacklist` parameter:
+ *
+ * {{{
+ * $this->Form->inputs(null, ['title']);
+ * }}}
+ *
+ * In the above example, no field would be generated for the title field.
+ *
* In addition to controller fields output, `$fields` can be used to control legend
* and fieldset rendering.
* `$this->Form->inputs('My legend');` Would generate an input set with a custom legend.
*
- * @param array $fields An array of fields to generate inputs for, or null.
- * @param array $blacklist A simple array of fields to not create inputs for.
+ * @param array $fields An array of customizations for the fields that will be
+ * generated. This array allows you to set custom types, labels, or other options.
+ * @param array $blacklist A list of fields to not create inputs for.
* @param array $options Options array. Valid keys are:
* - `fieldset` Set to false to disable the fieldset.
* - `legend` Set to false to disable the legend for the generated input set. Or supply a string
@@ -731,8 +740,6 @@ protected function _domId($value) {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::inputs
*/
public function inputs($fields = null, $blacklist = null, $options = array()) {
- $modelFields = [];
- $model = false;
$fieldset = $legend = true;
$context = $this->_getContext();
@@ -746,9 +753,11 @@ public function inputs($fields = null, $blacklist = null, $options = array()) {
$fields = [];
}
- if (empty($fields)) {
- $fields = $modelFields;
- }
+ $fields = array_merge(
+ Hash::normalize($modelFields),
+ Hash::normalize((array)$fields)
+ );
+
if (isset($options['legend'])) {
$legend = $options['legend'];
}
@@ -2548,15 +2548,38 @@ public function testFormInputsLegendFieldset() {
*/
public function testFormInputs() {
$this->Form->create($this->article);
- $result = $this->Form->inputs(['id', 'title', 'body']);
+ $result = $this->Form->inputs();
$expected = array(
'<fieldset',
'<legend', 'New Article', '/legend',
'input' => array('type' => 'hidden', 'name' => 'id', 'id' => 'id'),
+ array('div' => array('class' => 'input select required')),
+ '*/div',
array('div' => array('class' => 'input text required')),
'*/div',
array('div' => array('class' => 'input text')),
'*/div',
+ array('div' => array('class' => 'input text')),
+ '*/div',
+ '/fieldset',
+ );
+ $this->assertTags($result, $expected);
+
+ $result = $this->Form->inputs([
+ 'published' => ['type' => 'boolean']
+ ]);
+ $expected = array(
+ '<fieldset',
+ '<legend', 'New Article', '/legend',
+ 'input' => array('type' => 'hidden', 'name' => 'id', 'id' => 'id'),
+ array('div' => array('class' => 'input select required')),
+ '*/div',
+ array('div' => array('class' => 'input text required')),
+ '*/div',
+ array('div' => array('class' => 'input text')),
+ '*/div',
+ array('div' => array('class' => 'input boolean')),
+ '*/div',
'/fieldset',
);
$this->assertTags($result, $expected);

0 comments on commit 6fa3dfd

Please sign in to comment.