Nested optgroups (#470)
* fix optionGroup and added a function to handle recursively the arrays * simplify recursively * fix codestyle * fix codestyle * add new parameter annotation
This commit is contained in:
1 parent
a5f7464ee6
commit
cecb65626c
1 file changed
+9
-6
+9
-6
@@ -699,20 +699,23 @@ class FormBuilder
|
|||||||
* @param string $selected
|
* @param string $selected
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @param array $optionsAttributes
|
* @param array $optionsAttributes
|
||||||
|
* @param integer $level
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Support\HtmlString
|
* @return \Illuminate\Support\HtmlString
|
||||||
*/
|
*/
|
||||||
protected function optionGroup($list, $label, $selected, array $attributes = [], array $optionsAttributes = [])
|
protected function optionGroup($list, $label, $selected, array $attributes = [], array $optionsAttributes = [], $level = 0)
|
||||||
{
|
{
|
||||||
$html = [];
|
$html = [];
|
||||||
|
$space = str_repeat(" ", $level);
|
||||||
foreach ($list as $value => $display) {
|
foreach ($list as $value => $display) {
|
||||||
$optionAttributes = $optionsAttributes[$value] ?? [];
|
$optionAttributes = $optionsAttributes[$value] ?? [];
|
||||||
|
if (is_array($display)) {
|
||||||
$html[] = $this->option($display, $value, $selected, $optionAttributes);
|
$html[] = $this->optionGroup($display, $value, $selected, $attributes, $optionAttributes, $level+5);
|
||||||
|
} else {
|
||||||
|
$html[] = $this->option($space.$display, $value, $selected, $attributes, $optionAttributes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return $this->toHtmlString('<optgroup label="' . e($space.$label) . '">' . implode('', $html) . '</optgroup>');
|
||||||
return $this->toHtmlString('<optgroup label="' . e($label) . '"' . $this->html->attributes($attributes) . '>' . implode('', $html) . '</optgroup>');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user