mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01:00
AphrontFormSelectControl: Add <optgroup> to <select>
Summary: Add <optgroup> style selects, if the array of options is actually an array-of-arrays. Test Plan: Made one, it looked OK. Reviewers: epriestley Reviewed By: epriestley CC: aran Differential Revision: https://secure.phabricator.com/D2177
This commit is contained in:
parent
dea4901bb6
commit
8f70d891fa
1 changed files with 24 additions and 10 deletions
|
@ -49,16 +49,7 @@ final class AphrontFormSelectControl extends AphrontFormControl {
|
|||
array $options,
|
||||
array $attrs = array()) {
|
||||
|
||||
$option_tags = array();
|
||||
foreach ($options as $value => $label) {
|
||||
$option_tags[] = phutil_render_tag(
|
||||
'option',
|
||||
array(
|
||||
'selected' => ($value == $selected) ? 'selected' : null,
|
||||
'value' => $value,
|
||||
),
|
||||
phutil_escape_html($label));
|
||||
}
|
||||
$option_tags = self::renderOptions($selected, $options);
|
||||
|
||||
return javelin_render_tag(
|
||||
'select',
|
||||
|
@ -66,4 +57,27 @@ final class AphrontFormSelectControl extends AphrontFormControl {
|
|||
implode("\n", $option_tags));
|
||||
}
|
||||
|
||||
private static function renderOptions($selected, array $options) {
|
||||
$tags = array();
|
||||
foreach ($options as $value => $thing) {
|
||||
if (is_array($thing)) {
|
||||
$tags[] = phutil_render_tag(
|
||||
'optgroup',
|
||||
array(
|
||||
'label' => $value,
|
||||
),
|
||||
implode("\n", self::renderOptions($selected, $thing)));
|
||||
} else {
|
||||
$tags[] = phutil_render_tag(
|
||||
'option',
|
||||
array(
|
||||
'selected' => ($value == $selected) ? 'selected' : null,
|
||||
'value' => $value,
|
||||
),
|
||||
phutil_escape_html($thing));
|
||||
}
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue