18 if ( array_key_exists(
'other', $params ) ) {
20 } elseif ( array_key_exists(
'other-message', $params ) ) {
21 $params[
'other'] = $this->
getMessage( $params[
'other-message'] )->plain();
23 $params[
'other'] = $this->
msg(
'htmlform-selectorother-other' )->plain();
26 parent::__construct( $params );
30 throw new MWException(
'HTMLSelectAndOtherField called without any options' );
32 if ( !in_array(
'other', $this->mOptions,
true ) ) {
40 $select = parent::getInputHTML( $value[1] );
43 'id' => $this->mID .
'-other',
45 'class' => [
'mw-htmlform-select-and-other-field' ],
49 if ( $this->mClass !==
'' ) {
53 if ( isset( $this->mParams[
'maxlength-unit'] ) ) {
54 $textAttribs[
'data-mw-maxlength-unit'] = $this->mParams[
'maxlength-unit'];
69 $textbox = Html::input( $this->mName .
'-other', $value[2],
'text', $textAttribs );
71 return "$select<br />\n$textbox";
75 return [
'mediawiki.widgets.SelectWithInputWidget' ];
79 $this->mParent->getOutput()->addModuleStyles(
'mediawiki.widgets.SelectWithInputWidget.styles' );
83 'name' => $this->mName .
'-other',
96 $textAttribs += OOUI\Element::configFromHtmlAttributes(
100 if ( $this->mClass !==
'' ) {
105 $dropdownInputAttribs = [
107 'id' => $this->mID .
'-select',
109 'value' => $value[1],
117 $dropdownInputAttribs += OOUI\Element::configFromHtmlAttributes(
121 if ( $this->mClass !==
'' ) {
126 if ( isset( $this->mParams[
'disabled' ] ) && $this->mParams[
'disabled' ] ) {
132 'disabled' => $disabled,
133 'textinput' => $textAttribs,
134 'dropdowninput' => $dropdownInputAttribs,
136 'required' => $this->mParams[
'required' ] ??
false,
137 'classes' => [
'mw-htmlform-select-and-other-field' ],
139 'maxlengthUnit' => $this->mParams[
'maxlength-unit'] ??
'bytes'
152 $default = parent::getDefault();
159 if ( $default !==
null ) {
164 foreach ( $this->mFlatOptions as $option ) {
165 $match = $option . $this->
msg(
'colon-separator' )->inContentLanguage()->text();
166 if ( strpos( $final, $match ) === 0 ) {
168 $text = substr( $final, strlen( $match ) );
174 return [ $final, $list, $text ];
183 if ( $request->getCheck( $this->mName ) ) {
184 $list = $request->getText( $this->mName );
185 $text = $request->getText( $this->mName .
'-other' );
188 if ( $list ==
'other' ) {
190 } elseif ( !in_array( $list, $this->mFlatOptions,
true ) ) {
191 # User has spoofed the select form to give an option which wasn't
192 # in the original offer. Sulk...
194 } elseif ( $text ==
'' ) {
197 $final = $list . $this->
msg(
'colon-separator' )->inContentLanguage()->text() . $text;
199 return [ $final, $list, $text ];
205 return $this->mParams[
'size'] ?? 45;
209 # HTMLSelectField forces $value to be one of the options in the select
210 # field, which is not useful here. But we do want the validation further up
212 $p = parent::validate( $value[1], $alldata );
218 if ( isset( $this->mParams[
'required'] )
219 && $this->mParams[
'required'] !==
false
222 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.
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
__construct( $params)
Initialise the object.
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
loadDataFromRequest( $request)
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.