Sn1per has uploaded a new change for review. https://gerrit.wikimedia.org/r/238075
Change subject: Enable multiple default values for XmlSelect ...................................................................... Enable multiple default values for XmlSelect Useful for when a <select> tag with the 'multiple' attribute is needed. Bug: T93234 Change-Id: Ib83aed3392cf15cce4637fac56979a0f6b3d6b2f --- M includes/XmlSelect.php 1 file changed, 7 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/75/238075/1 diff --git a/includes/XmlSelect.php b/includes/XmlSelect.php index e765eed..78f4764 100644 --- a/includes/XmlSelect.php +++ b/includes/XmlSelect.php @@ -43,7 +43,7 @@ } /** - * @param string $default + * @param string|array $default */ public function setDefault( $default ) { $this->default = $default; @@ -95,7 +95,7 @@ * label => ( label => value, label => value ) * * @param array $options - * @param string $default + * @param string|array $default * @return string */ static function formatOptions( $options, $default = false ) { @@ -106,7 +106,11 @@ $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"; } } -- To view, visit https://gerrit.wikimedia.org/r/238075 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib83aed3392cf15cce4637fac56979a0f6b3d6b2f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Sn1per <geof...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits