Skip to content

Commit 06d63a3

Browse files
committed
add test case and fixed bug
1 parent 5ec486d commit 06d63a3

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

Test/Case/View/Helper/BoostCakeFormHelperTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,34 @@ public function testSelectMultipleCheckbox() {
227227
'/label'
228228
));
229229

230+
$result = $this->Form->select('name',
231+
array(
232+
1 => 'one',
233+
2 => 'two',
234+
3 => 'three'
235+
),
236+
array(
237+
'multiple' => 'checkbox',
238+
'class' => 'checkbox-inline',
239+
'value' => 2
240+
)
241+
);
242+
$this->assertTags($result, array(
243+
array('input' => array('type' => 'hidden', 'name' => 'data[name]', 'value' => '', 'id' => 'name')),
244+
array('label' => array('for' => 'Name1', 'class' => 'checkbox-inline')),
245+
array('input' => array('type' => 'checkbox', 'name' => 'data[name][]', 'value' => '1', 'id' => 'Name1')),
246+
' one',
247+
'/label',
248+
array('label' => array('for' => 'Name2', 'class' => 'selected checkbox-inline')),
249+
array('input' => array('type' => 'checkbox', 'name' => 'data[name][]', 'value' => '2', 'id' => 'Name2', 'checked' => 'checked')),
250+
' two',
251+
'/label',
252+
array('label' => array('for' => 'Name3', 'class' => 'checkbox-inline')),
253+
array('input' => array('type' => 'checkbox', 'name' => 'data[name][]', 'value' => '3', 'id' => 'Name3')),
254+
' three',
255+
'/label'
256+
));
257+
230258
$result = $this->Form->select('name',
231259
array(
232260
1 => 'bill',

View/Helper/BoostCakeFormHelper.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,13 @@ protected function _selectOptions($elements = array(), $parents = array(), $show
214214
$option = preg_replace('/<div.*?>/', '', $option);
215215
$option = preg_replace('/<\/div>/', '', $option);
216216
if (preg_match('/>(<label.*?>)/', $option, $match)) {
217+
$class = $attributes['class'];
217218
if (preg_match('/.* class="(.*)".*/', $match[1], $classMatch)) {
218-
$attributes['class'] = $classMatch[1] . ' ' . $attributes['class'];
219-
$match[1] = str_replace('class="' . $classMatch[1] . '"', '', $match[1]);
219+
$class = $classMatch[1] . ' ' . $attributes['class'];
220+
$match[1] = str_replace(' class="' . $classMatch[1] . '"', '', $match[1]);
220221
}
221222
$option = $match[1] . preg_replace('/<label.*?>/', ' ', $option);
222-
if (isset($attributes['class'])) {
223-
$option = preg_replace('/(<label.*?)(>)/', '$1 class="' . $attributes['class'] . '"$2', $option);
224-
}
223+
$option = preg_replace('/(<label.*?)(>)/', '$1 class="' . $class . '"$2', $option);
225224
}
226225
$selectOptions[$key] = $option;
227226
}

0 commit comments

Comments
 (0)