Merge pull request #567 from marc1706/ticket/565
[ticket/565] Properly create select box for multiple options
This commit is contained in:
@@ -78,15 +78,16 @@ class modules_helper
|
||||
* @param string $key Key of select box
|
||||
* @param array $select_ary Array of select box options
|
||||
* @param array $selected_options Array of selected options
|
||||
* @param bool $multiple Whether multiple options should be selectable
|
||||
*
|
||||
* @return string HTML code of select box
|
||||
* @access public
|
||||
*/
|
||||
public function generate_select_box($key, $select_ary, $selected_options)
|
||||
public function generate_select_box($key, $select_ary, $selected_options, $multiple = false)
|
||||
{
|
||||
// Build options
|
||||
$options = '<select id="' . $key . '" name="' . $key;
|
||||
$options .= (sizeof($selected_options) > 1) ? '[]" multiple="multiple">' : '">';
|
||||
$options .= ($multiple) ? '[]" multiple="multiple">' : '">';
|
||||
foreach ($select_ary as $id => $option)
|
||||
{
|
||||
$options .= '<option value="' . $option['value'] . '"' . ((in_array($option['value'], $selected_options)) ? ' selected="selected"' : '') . (!empty($option['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $option['title'] . '</option>';
|
||||
@@ -114,11 +115,6 @@ class modules_helper
|
||||
{
|
||||
$selected_options = explode(',', $this->config[$key]);
|
||||
}
|
||||
// Add useless values to force multi drop down list
|
||||
$selected_options += array(
|
||||
'-1' => '',
|
||||
'-2' => '',
|
||||
);
|
||||
|
||||
// Build forum options
|
||||
foreach ($forum_list as $f_id => $f_row)
|
||||
@@ -130,7 +126,7 @@ class modules_helper
|
||||
);
|
||||
}
|
||||
|
||||
return $this->generate_select_box($key, $select_ary, $selected_options);
|
||||
return $this->generate_select_box($key, $select_ary, $selected_options, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -191,7 +191,7 @@ class attachments extends module_base
|
||||
|
||||
$selected = $this->get_selected_filetypes($module_id);
|
||||
|
||||
return $this->helper->generate_select_box($key, $extensions, $selected);
|
||||
return $this->helper->generate_select_box($key, $extensions, $selected, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -93,16 +93,17 @@ class board3_includes_modules_helper_test extends \board3\portal\tests\testframe
|
||||
'title' => 'three',
|
||||
),
|
||||
),
|
||||
array('one', 'two')),
|
||||
array('one', 'two'),
|
||||
true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_generate_select_box
|
||||
*/
|
||||
public function test_generate_select_box($expected, $key, $select_ary, $selected_options)
|
||||
public function test_generate_select_box($expected, $key, $select_ary, $selected_options, $multiple = false)
|
||||
{
|
||||
$this->assertEquals($expected, $this->modules_helper->generate_select_box($key, $select_ary, $selected_options));
|
||||
$this->assertEquals($expected, $this->modules_helper->generate_select_box($key, $select_ary, $selected_options, $multiple));
|
||||
}
|
||||
|
||||
public function test_generate_forum_select()
|
||||
|
||||
Reference in New Issue
Block a user