12 private const FIELD_CLASS =
'mw-htmlform-select-or-other';
19 parent::__construct( $params );
21 if ( !in_array(
'other', $this->mOptions,
true ) ) {
23 $params[
'other'] ??
wfMessage(
'htmlform-selectorother-other' )->text();
32 if ( $value !==
false ) {
33 $value = strval( $value );
34 $valInSelect = in_array(
39 $selected = $valInSelect ? $value :
'other';
41 $select =
new XmlSelect( $this->mName,
false, $selected );
44 $tbAttribs = [
'size' => $this->
getSize() ];
46 if ( !empty( $this->mParams[
'disabled'] ) ) {
47 $select->setAttribute(
'disabled',
'disabled' );
48 $tbAttribs[
'disabled'] =
'disabled';
51 if ( isset( $this->mParams[
'tabindex'] ) ) {
52 $select->setAttribute(
'tabindex', $this->mParams[
'tabindex'] );
53 $tbAttribs[
'tabindex'] = $this->mParams[
'tabindex'];
56 $select = $select->getHTML();
58 if ( isset( $this->mParams[
'maxlength'] ) ) {
59 $tbAttribs[
'maxlength'] = $this->mParams[
'maxlength'];
62 $textbox = Html::input( $this->mName .
'-other', $valInSelect ?
'' : $value,
'text', $tbAttribs );
66 'class' => self::FIELD_CLASS
68 if ( $this->mClass !==
'' ) {
71 return Html::rawElement(
74 "$select<br />\n$textbox"
83 return [
'mediawiki.widgets.SelectWithInputWidget' ];
87 $this->mParent->getOutput()->addModuleStyles(
'mediawiki.widgets.SelectWithInputWidget.styles' );
90 if ( $value !==
false ) {
91 $value = strval( $value );
92 $valInSelect = in_array(
101 'value' => $valInSelect ? $value :
'other',
109 $dropdownAttribs += OOUI\Element::configFromHtmlAttributes(
115 'name' => $this->mName .
'-other',
117 'value' => $valInSelect ?
'' : $value,
129 $textAttribs += OOUI\Element::configFromHtmlAttributes(
133 if ( $this->mPlaceholder !==
'' ) {
138 if ( isset( $this->mParams[
'disabled' ] ) && $this->mParams[
'disabled' ] ) {
142 $inputClasses = [ self::FIELD_CLASS ];
143 if ( $this->mClass !==
'' ) {
144 $inputClasses = array_merge( $inputClasses, explode(
' ', $this->mClass ) );
148 'classes' => $inputClasses,
149 'disabled' => $disabled,
150 'textinput' => $textAttribs,
151 'dropdowninput' => $dropdownAttribs,
152 'required' => $this->mParams[
'required' ] ??
false,
167 if ( $request->getCheck( $this->mName ) ) {
168 $val = $request->getText( $this->mName );
170 if ( $val ===
'other' ) {
171 $val = $request->getText( $this->mName .
'-other' );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Select dropdown field, with an additional "other" textbox.
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...
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
loadDataFromRequest( $request)
shouldInfuseOOUI()
Whether the field should be automatically infused.
Class for generating HTML <select> or <datalist> elements.