19 private const FIELD_CLASS =
'mw-htmlform-select-and-other-field';
21 private $mFlatOptions;
28 if ( array_key_exists(
'other', $params ) ) {
30 } elseif ( array_key_exists(
'other-message', $params ) ) {
31 $params[
'other'] = $this->
getMessage( $params[
'other-message'] )->plain();
33 $params[
'other'] = $this->
msg(
'htmlform-selectorother-other' )->plain();
36 parent::__construct( $params );
39 throw new InvalidArgumentException(
'HTMLSelectAndOtherField called without any options' );
41 if ( !in_array(
'other', $this->mOptions,
true ) ) {
49 $select = parent::getInputHTML( $value[1] );
55 if ( isset( $this->mParams[
'maxlength-unit'] ) ) {
56 $textAttribs[
'data-mw-maxlength-unit'] = $this->mParams[
'maxlength-unit'];
71 $textbox = Html::input( $this->mName .
'-other', $value[2],
'text', $textAttribs );
75 'class' => self::FIELD_CLASS
77 if ( $this->mClass !==
'' ) {
80 return Html::rawElement(
83 "$select<br />\n$textbox"
88 return [
'mediawiki.widgets.SelectWithInputWidget' ];
92 $this->mParent->getOutput()->addModuleStyles(
'mediawiki.widgets.SelectWithInputWidget.styles' );
96 'name' => $this->mName .
'-other',
109 $textAttribs += OOUI\Element::configFromHtmlAttributes(
114 $dropdownInputAttribs = [
117 'value' => $value[1],
125 $dropdownInputAttribs += OOUI\Element::configFromHtmlAttributes(
130 if ( isset( $this->mParams[
'disabled' ] ) && $this->mParams[
'disabled' ] ) {
134 $inputClasses = [ self::FIELD_CLASS ];
135 if ( $this->mClass !==
'' ) {
136 $inputClasses = array_merge( $inputClasses, explode(
' ', $this->mClass ) );
140 'disabled' => $disabled,
141 'textinput' => $textAttribs,
142 'dropdowninput' => $dropdownInputAttribs,
144 'required' => $this->mParams[
'required' ] ??
false,
145 'classes' => $inputClasses,
147 'maxlengthUnit' => $this->mParams[
'maxlength-unit'] ??
'bytes'
165 $default = parent::getDefault();
172 if ( $default !==
null ) {
177 foreach ( $this->mFlatOptions as $option ) {
178 $match = $option . $this->
msg(
'colon-separator' )->inContentLanguage()->text();
179 if ( str_starts_with( $final, $match ) ) {
181 $text = substr( $final, strlen( $match ) );
187 return [ $final, $list, $text ];
196 if ( $request->getCheck( $this->mName ) ) {
197 $list = $request->getText( $this->mName );
198 $text = $request->getText( $this->mName .
'-other' );
201 if ( $list ==
'other' ) {
203 } elseif ( !in_array( $list, $this->mFlatOptions,
true ) ) {
204 # User has spoofed the select form to give an option which wasn't
205 # in the original offer. Sulk...
207 } elseif ( $text ==
'' ) {
210 $final = $list . $this->
msg(
'colon-separator' )->inContentLanguage()->text() . $text;
212 return [ $final, $list, $text ];
218 return $this->mParams[
'size'] ?? 45;
222 # HTMLSelectField forces $value to be one of the options in the select
223 # field, which is not useful here. But we do want the validation further up
225 $p = parent::validate( $value[1], $alldata );
231 if ( isset( $this->mParams[
'required'] )
232 && $this->mParams[
'required'] !==
false
235 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...