Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reduce the number of templates used.
By adding {{attrs}} I can re-add support for arbitrary properties on
option elements. As well as the [name => foo, value => bar] format for
option elements.
  • Loading branch information
markstory committed Jan 8, 2014
1 parent a2d7f8d commit de15f68
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
16 changes: 8 additions & 8 deletions Cake/View/Input/SelectBox.php
Expand Up @@ -137,19 +137,19 @@ protected function _renderOptions($options, $disabled, $selected, $escape) {
'content' => implode('', $groupOptions)
]);
} else {
$template = 'option';
$isSelected = $this->_isSelected($key, $selected);
$isDisabled = $this->_isDisabled($key, $disabled);
if ($isSelected) {
$template .= 'Selected';
$optAttrs = [];
if ($this->_isSelected($key, $selected)) {
$optAttrs['selected'] = true;
}
if ($isDisabled) {
$template .= 'Disabled';
if ($this->_isDisabled($key, $disabled)) {
$optAttrs['disabled'] = true;
}
$optAttrs['escape'] = $escape;

$out[] = $this->_templates->format($template, [
$out[] = $this->_templates->format('option', [
'name' => $escape ? h($key) : $key,
'value' => $escape ? h($val) : $val,
'attrs' => $this->_templates->formatAttributes($optAttrs),
]);
}
}
Expand Down
5 changes: 1 addition & 4 deletions Test/TestCase/View/Input/SelectBoxTest.php
Expand Up @@ -27,10 +27,7 @@ public function setUp() {
parent::setUp();
$templates = [
'select' => '<select name="{{name}}"{{attrs}}>{{content}}</select>',
'option' => '<option value="{{name}}">{{value}}</option>',
'optionSelected' => '<option value="{{name}}" selected="selected">{{value}}</option>',
'optionDisabled' => '<option value="{{name}}" disabled="disabled">{{value}}</option>',
'optionSelectedDisabled' => '<option value="{{name}}" selected="selected" disabled="disabled">{{value}}</option>',
'option' => '<option value="{{name}}"{{attrs}}>{{value}}</option>',
'optgroup' => '<optgroup label="{{label}}">{{content}}</optgroup>',
];
$this->templates = new StringTemplate();
Expand Down

0 comments on commit de15f68

Please sign in to comment.