18 private const FIELD_CLASS =
'mw-htmlform-select-and-other-field';
20 private $mFlatOptions;
27 if ( array_key_exists(
'other', $params ) ) {
29 } elseif ( array_key_exists(
'other-message', $params ) ) {
30 $params[
'other'] = $this->
getMessage( $params[
'other-message'] )->plain();
32 $params[
'other'] = $this->
msg(
'htmlform-selectorother-other' )->plain();
35 parent::__construct( $params );
38 throw new InvalidArgumentException(
'HTMLSelectAndOtherField called without any options' );
40 if ( !in_array(
'other', $this->mOptions,
true ) ) {
48 $select = parent::getInputHTML( $value[1] );
54 if ( isset( $this->mParams[
'maxlength-unit'] ) ) {
55 $textAttribs[
'data-mw-maxlength-unit'] = $this->mParams[
'maxlength-unit'];
70 $textbox = Html::input( $this->mName .
'-other', $value[2],
'text', $textAttribs );
74 'class' => self::FIELD_CLASS
76 if ( $this->mClass !==
'' ) {
79 return Html::rawElement(
82 "$select<br />\n$textbox"
87 return [
'mediawiki.widgets.SelectWithInputWidget' ];
91 $this->mParent->getOutput()->addModuleStyles(
'mediawiki.widgets.SelectWithInputWidget.styles' );
95 'name' => $this->mName .
'-other',
108 $textAttribs += OOUI\Element::configFromHtmlAttributes(
113 $dropdownInputAttribs = [
116 'value' => $value[1],
124 $dropdownInputAttribs += OOUI\Element::configFromHtmlAttributes(
129 if ( isset( $this->mParams[
'disabled' ] ) && $this->mParams[
'disabled' ] ) {
133 $inputClasses = [ self::FIELD_CLASS ];
134 if ( $this->mClass !==
'' ) {
135 $inputClasses = array_merge( $inputClasses, explode(
' ', $this->mClass ) );
139 'disabled' => $disabled,
140 'textinput' => $textAttribs,
141 'dropdowninput' => $dropdownInputAttribs,
143 'required' => $this->mParams[
'required' ] ??
false,
144 'classes' => $inputClasses,
146 'maxlengthUnit' => $this->mParams[
'maxlength-unit'] ??
'bytes'
164 $default = parent::getDefault();
171 if ( $default !==
null ) {
176 foreach ( $this->mFlatOptions as $option ) {
177 $match = $option . $this->
msg(
'colon-separator' )->inContentLanguage()->text();
178 if ( str_starts_with( $final, $match ) ) {
180 $text = substr( $final, strlen( $match ) );
186 return [ $final, $list, $text ];
195 if ( $request->getCheck( $this->mName ) ) {
196 $list = $request->getText( $this->mName );
197 $text = $request->getText( $this->mName .
'-other' );
200 if ( $list ==
'other' ) {
202 } elseif ( !in_array( $list, $this->mFlatOptions,
true ) ) {
203 # User has spoofed the select form to give an option which wasn't
204 # in the original offer. Sulk...
206 } elseif ( $text ==
'' ) {
209 $final = $list . $this->
msg(
'colon-separator' )->inContentLanguage()->text() . $text;
211 return [ $final, $list, $text ];
217 return $this->mParams[
'size'] ?? 45;
221 # HTMLSelectField forces $value to be one of the options in the select
222 # field, which is not useful here. But we do want the validation further up
224 $p = parent::validate( $value[1], $alldata );
230 if ( isset( $this->mParams[
'required'] )
231 && $this->mParams[
'required'] !==
false
234 return $this->
msg(
'htmlform-required' );
Double field with a dropdown list constructed from a system message in the format.
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
getDefault()
Stability: stableto override mixed
loadDataFromRequest( $request)
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.Don't forget to call pare...