23 if ( array_key_exists(
'other', $params ) ) {
25 } elseif ( array_key_exists(
'other-message', $params ) ) {
26 $params[
'other'] = $this->
getMessage( $params[
'other-message'] )->plain();
28 $params[
'other'] = $this->
msg(
'htmlform-selectorother-other' )->plain();
31 parent::__construct( $params );
35 throw new MWException(
'HTMLSelectAndOtherField called without any options' );
37 if ( !in_array(
'other', $this->mOptions,
true ) ) {
45 $select = parent::getInputHTML( $value[1] );
48 'id' => $this->mID .
'-other',
50 'class' => [
'mw-htmlform-select-and-other-field' ],
54 if ( $this->mClass !==
'' ) {
58 if ( isset( $this->mParams[
'maxlength-unit'] ) ) {
59 $textAttribs[
'data-mw-maxlength-unit'] = $this->mParams[
'maxlength-unit'];
74 $textbox = Html::input( $this->mName .
'-other', $value[2],
'text', $textAttribs );
76 return "$select<br />\n$textbox";
80 return [
'mediawiki.widgets.SelectWithInputWidget' ];
84 $this->mParent->getOutput()->addModuleStyles(
'mediawiki.widgets.SelectWithInputWidget.styles' );
88 'name' => $this->mName .
'-other',
101 $textAttribs += OOUI\Element::configFromHtmlAttributes(
105 if ( $this->mClass !==
'' ) {
110 $dropdownInputAttribs = [
112 'id' => $this->mID .
'-select',
114 'value' => $value[1],
122 $dropdownInputAttribs += OOUI\Element::configFromHtmlAttributes(
126 if ( $this->mClass !==
'' ) {
131 if ( isset( $this->mParams[
'disabled' ] ) && $this->mParams[
'disabled' ] ) {
137 'disabled' => $disabled,
138 'textinput' => $textAttribs,
139 'dropdowninput' => $dropdownInputAttribs,
141 'required' => $this->mParams[
'required' ] ??
false,
142 'classes' => [
'mw-htmlform-select-and-other-field' ],
144 'maxlengthUnit' => $this->mParams[
'maxlength-unit'] ??
'bytes'
161 $default = parent::getDefault();
168 if ( $default !==
null ) {
173 foreach ( $this->mFlatOptions as $option ) {
174 $match = $option . $this->
msg(
'colon-separator' )->inContentLanguage()->text();
175 if ( strpos( $final, $match ) === 0 ) {
177 $text = substr( $final, strlen( $match ) );
183 return [ $final, $list, $text ];
192 if ( $request->getCheck( $this->mName ) ) {
193 $list = $request->getText( $this->mName );
194 $text = $request->getText( $this->mName .
'-other' );
197 if ( $list ==
'other' ) {
199 } elseif ( !in_array( $list, $this->mFlatOptions,
true ) ) {
200 # User has spoofed the select form to give an option which wasn't
201 # in the original offer. Sulk...
203 } elseif ( $text ==
'' ) {
206 $final = $list . $this->
msg(
'colon-separator' )->inContentLanguage()->text() . $text;
208 return [ $final, $list, $text ];
214 return $this->mParams[
'size'] ?? 45;
218 # HTMLSelectField forces $value to be one of the options in the select
219 # field, which is not useful here. But we do want the validation further up
221 $p = parent::validate( $value[1], $alldata );
227 if ( isset( $this->mParams[
'required'] )
228 && $this->mParams[
'required'] !==
false
231 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....
__construct( $params)
Initialise the object.
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
getDefault()
Stable to 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...
getInputWidget( $params)
Stable to override