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:
Lluís Bayer Soler authored and Tom Shafer committed 2018-02-05 07:04:30 -07:00
1 parent a5f7464ee6
commit cecb65626c
1 file changed
+9 -6
+9 -6
View File
@@ -699,20 +699,23 @@ class FormBuilder
* @param string $selected
* @param array $attributes
* @param array $optionsAttributes
* @param integer $level
*
* @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 = [];
$space = str_repeat(" ", $level);
foreach ($list as $value => $display) {
$optionAttributes = $optionsAttributes[$value] ?? [];
$html[] = $this->option($display, $value, $selected, $optionAttributes);
if (is_array($display)) {
$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($label) . '"' . $this->html->attributes($attributes) . '>' . implode('', $html) . '</optgroup>');
return $this->toHtmlString('<optgroup label="' . e($space.$label) . '">' . implode('', $html) . '</optgroup>');
}
/**