Skip to content

Commit

Permalink
Remove legend/fieldset classnames.
Browse files Browse the repository at this point in the history
This formatting should be handled with templates now.
  • Loading branch information
markstory committed Mar 4, 2014
1 parent 6d1c29f commit 417bfd8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
16 changes: 5 additions & 11 deletions src/View/Helper/FormHelper.php
Expand Up @@ -142,11 +142,13 @@ class FormHelper extends Helper {
'errorList' => '<ul>{{content}}</ul>',
'errorItem' => '<li>{{text}}</li>',
'file' => '<input type="file" name="{{name}}"{{attrs}}>',
'fieldset' => '<fieldset>{{content}}</fieldset>',
'formstart' => '<form{{attrs}}>',
'formend' => '</form>',
'hiddenblock' => '<div style="display:none;">{{content}}</div>',
'input' => '<input type="{{type}}" name="{{name}}"{{attrs}}>',
'label' => '<label{{attrs}}>{{text}}</label>',
'legend' => '<legend>{{text}}</legend>',
'option' => '<option value="{{value}}"{{attrs}}>{{text}}</option>',
'optgroup' => '<optgroup label="{{label}}"{{attrs}}>{{content}}</optgroup>',
'select' => '<select name="{{name}}"{{attrs}}>{{content}}</select>',
Expand Down Expand Up @@ -724,8 +726,7 @@ protected function _domId($value) {
* @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 $options Options array. Valid keys are:
* - `fieldset` Set to false to disable the fieldset. If a string is supplied it will be used as
* the class name for the fieldset element.
* - `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
* to customize the legend text.
* @return string Completed form inputs.
Expand Down Expand Up @@ -794,18 +795,11 @@ public function inputs($fields = null, $blacklist = null, $options = array()) {
$out .= $this->input($name, $options);
}

if (is_string($fieldset)) {
$fieldsetClass = sprintf(' class="%s"', $fieldset);
} else {
$fieldsetClass = '';
}

// TODO cleanup HTML helper usage.
if ($fieldset) {
if ($legend) {
$out = $this->Html->useTag('legend', $legend) . $out;
$out = $this->formatTemplate('legend', ['text' => $legend]) . $out;
}
$out = $this->Html->useTag('fieldset', $fieldsetClass, $out);
$out = $this->formatTemplate('fieldset', ['content' => $out]);
}
return $out;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -2510,20 +2510,20 @@ public function testFormInputsLegendFieldset() {
);
$this->assertTags($result, $expected);

$result = $this->Form->inputs(array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
$result = $this->Form->inputs(array('legend' => 'Field of Dreams', 'fieldset' => true));
$expected = array(
'fieldset' => array('class' => 'classy-stuff'),
'<fieldset',
'<legend',
'Field of Dreams',
'/legend',
'*/fieldset'
);
$this->assertTags($result, $expected);

$result = $this->Form->inputs(null, null, array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
$result = $this->Form->inputs(null, null, array('legend' => 'Field of Dreams', 'fieldset' => true));
$this->assertTags($result, $expected);

$result = $this->Form->inputs('Field of Dreams', null, array('fieldset' => 'classy-stuff'));
$result = $this->Form->inputs('Field of Dreams', null, array('fieldset' => true));
$this->assertTags($result, $expected);

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

0 comments on commit 417bfd8

Please sign in to comment.