X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fhtmlform%2Ffields%2FHTMLSelectAndOtherField.php;h=354432bb28c3bc1bd2e982dbdec5e1f47c2420c0;hb=d3a30a3c58dfa795f4d236f23a99b64d094e6337;hp=4e64e9d7cbc33505a294131c9025021d59d463a7;hpb=e8efad4669679f5845d3837558043fe1cd4e7833;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/htmlform/fields/HTMLSelectAndOtherField.php b/includes/htmlform/fields/HTMLSelectAndOtherField.php index 4e64e9d7cb..354432bb28 100644 --- a/includes/htmlform/fields/HTMLSelectAndOtherField.php +++ b/includes/htmlform/fields/HTMLSelectAndOtherField.php @@ -130,6 +130,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField { 'textinput' => $textAttribs, 'dropdowninput' => $dropdownInputAttribs, 'or' => false, + 'required' => $this->mParams[ 'required' ] ?? false, 'classes' => [ 'mw-htmlform-select-and-other-field' ], 'data' => [ 'maxlengthUnit' => $this->mParams['maxlength-unit'] ?? 'bytes' @@ -141,10 +142,39 @@ class HTMLSelectAndOtherField extends HTMLSelectField { return new MediaWiki\Widget\SelectWithInputWidget( $params ); } + /** + * @inheritDoc + */ + public function getDefault() { + $default = parent::getDefault(); + + // Default values of empty form + $final = ''; + $list = 'other'; + $text = ''; + + if ( $default !== null ) { + $final = $default; + // Assume the default is a text value, with the 'other' option selected. + // Then check if that assumption is correct, and update $list and $text if not. + $text = $final; + foreach ( $this->mFlatOptions as $option ) { + $match = $option . $this->msg( 'colon-separator' )->inContentLanguage()->text(); + if ( strpos( $final, $match ) === 0 ) { + $list = $option; + $text = substr( $final, strlen( $match ) ); + break; + } + } + } + + return [ $final, $list, $text ]; + } + /** * @param WebRequest $request * - * @return array("","",""] */ public function loadDataFromRequest( $request ) { if ( $request->getCheck( $this->mName ) ) { @@ -163,22 +193,9 @@ class HTMLSelectAndOtherField extends HTMLSelectField { } else { $final = $list . $this->msg( 'colon-separator' )->inContentLanguage()->text() . $text; } - } else { - $final = $this->getDefault(); - - $list = 'other'; - $text = $final; - foreach ( $this->mFlatOptions as $option ) { - $match = $option . $this->msg( 'colon-separator' )->inContentLanguage()->text(); - if ( strpos( $text, $match ) === 0 ) { - $list = $option; - $text = substr( $text, strlen( $match ) ); - break; - } - } + return [ $final, $list, $text ]; } - - return [ $final, $list, $text ]; + return $this->getDefault(); } public function getSize() { @@ -197,7 +214,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField { if ( isset( $this->mParams['required'] ) && $this->mParams['required'] !== false - && $value[1] === '' + && $value[0] === '' ) { return $this->msg( 'htmlform-required' ); }