Merge pull request #641 from crynobone/feature/form-select-optgroup
Add support for Form::select with optgroup, solved #526
This commit is contained in:
commit
287f2a299f
|
@ -397,12 +397,39 @@ public static function select($name, $options = array(), $selected = null, $attr
|
||||||
|
|
||||||
foreach ($options as $value => $display)
|
foreach ($options as $value => $display)
|
||||||
{
|
{
|
||||||
$html[] = static::option($value, $display, $selected);
|
if (is_array($display))
|
||||||
|
{
|
||||||
|
$html[] = static::optgroup($display, $value, $selected);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$html[] = static::option($value, $display, $selected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return '<select'.HTML::attributes($attributes).'>'.implode('', $html).'</select>';
|
return '<select'.HTML::attributes($attributes).'>'.implode('', $html).'</select>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a HTML select element optgroup.
|
||||||
|
*
|
||||||
|
* @param array $options
|
||||||
|
* @param string $label
|
||||||
|
* @param string $selected
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function optgroup($options, $label, $selected)
|
||||||
|
{
|
||||||
|
$html = array();
|
||||||
|
|
||||||
|
foreach ($options as $value => $display)
|
||||||
|
{
|
||||||
|
$html[] = static::option($value, $display, $selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
return '<optgroup label="'.HTML::entities($label).'">'.implode('', $html).'</option>';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a HTML select element option.
|
* Create a HTML select element option.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue