Useful for when a <select> tag with the 'multiple' attribute is
needed.
Bug: T93234
Change-Id: Ib83aed3392cf15cce4637fac56979a0f6b3d6b2f
- * @param string $default
+ * @param string|array $default
*/
public function setDefault( $default ) {
$this->default = $default;
*/
public function setDefault( $default ) {
$this->default = $default;
* label => ( label => value, label => value )
*
* @param array $options
* label => ( label => value, label => value )
*
* @param array $options
- * @param string $default
+ * @param string|array $default
* @return string
*/
static function formatOptions( $options, $default = false ) {
* @return string
*/
static function formatOptions( $options, $default = false ) {
$contents = self::formatOptions( $value, $default );
$data .= Html::rawElement( 'optgroup', array( 'label' => $label ), $contents ) . "\n";
} else {
$contents = self::formatOptions( $value, $default );
$data .= Html::rawElement( 'optgroup', array( 'label' => $label ), $contents ) . "\n";
} else {
- $data .= Xml::option( $label, $value, $value === $default ) . "\n";
+ // If $default is an array, then the <select> probably has the multiple attribute,
+ // so we should check if each $value is in $default, rather than checking if
+ // $value is equal to $default.
+ $selected = is_array( $default ) ? in_array( $value, $default ) : $value === $default;
+ $data .= Xml::option( $label, $value, $selected ) . "\n";