mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-10 23:01:04 +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 $options,
|
||||||
array $attrs = array()) {
|
array $attrs = array()) {
|
||||||
|
|
||||||
$option_tags = array();
|
$option_tags = self::renderOptions($selected, $options);
|
||||||
foreach ($options as $value => $label) {
|
|
||||||
$option_tags[] = phutil_render_tag(
|
|
||||||
'option',
|
|
||||||
array(
|
|
||||||
'selected' => ($value == $selected) ? 'selected' : null,
|
|
||||||
'value' => $value,
|
|
||||||
),
|
|
||||||
phutil_escape_html($label));
|
|
||||||
}
|
|
||||||
|
|
||||||
return javelin_render_tag(
|
return javelin_render_tag(
|
||||||
'select',
|
'select',
|
||||||
|
@ -66,4 +57,27 @@ final class AphrontFormSelectControl extends AphrontFormControl {
|
||||||
implode("\n", $option_tags));
|
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