24 if ( array_key_exists(
'other', $params ) ) {
26 } elseif ( array_key_exists(
'other-message', $params ) ) {
27 $params[
'other'] = $this->
getMessage( $params[
'other-message'] )->plain();
29 $params[
'other'] = $this->
msg(
'htmlform-selectorother-other' )->plain();
32 parent::__construct( $params );
36 throw new MWException(
'HTMLSelectAndOtherField called without any options' );
38 if ( !in_array(
'other', $this->mOptions,
true ) ) {
46 $select = parent::getInputHTML( $value[1] );
49 'id' => $this->mID .
'-other',
51 'class' => [
'mw-htmlform-select-and-other-field' ],
55 if ( $this->mClass !==
'' ) {
59 if ( isset( $this->mParams[
'maxlength-unit'] ) ) {
60 $textAttribs[
'data-mw-maxlength-unit'] = $this->mParams[
'maxlength-unit'];
75 $textbox = Html::input( $this->mName .
'-other', $value[2],
'text', $textAttribs );
77 return "$select<br />\n$textbox";
81 return [
'mediawiki.widgets.SelectWithInputWidget' ];
85 $this->mParent->getOutput()->addModuleStyles(
'mediawiki.widgets.SelectWithInputWidget.styles' );
89 'name' => $this->mName .
'-other',
102 $textAttribs += OOUI\Element::configFromHtmlAttributes(
106 if ( $this->mClass !==
'' ) {
111 $dropdownInputAttribs = [
113 'id' => $this->mID .
'-select',
115 'value' => $value[1],
123 $dropdownInputAttribs += OOUI\Element::configFromHtmlAttributes(
127 if ( $this->mClass !==
'' ) {
132 if ( isset( $this->mParams[
'disabled' ] ) && $this->mParams[
'disabled' ] ) {
138 'disabled' => $disabled,
139 'textinput' => $textAttribs,
140 'dropdowninput' => $dropdownInputAttribs,
142 'required' => $this->mParams[
'required' ] ??
false,
143 'classes' => [
'mw-htmlform-select-and-other-field' ],
145 'maxlengthUnit' => $this->mParams[
'maxlength-unit'] ??
'bytes'
162 $default = parent::getDefault();
169 if ( $default !==
null ) {
174 foreach ( $this->mFlatOptions as $option ) {
175 $match = $option . $this->
msg(
'colon-separator' )->inContentLanguage()->text();
176 if ( strpos( $final, $match ) === 0 ) {
178 $text = substr( $final, strlen( $match ) );
184 return [ $final, $list, $text ];
193 if ( $request->getCheck( $this->mName ) ) {
194 $list = $request->getText( $this->mName );
195 $text = $request->getText( $this->mName .
'-other' );
198 if ( $list ==
'other' ) {
200 } elseif ( !in_array( $list, $this->mFlatOptions,
true ) ) {
201 # User has spoofed the select form to give an option which wasn't
202 # in the original offer. Sulk...
204 } elseif ( $text ==
'' ) {
207 $final = $list . $this->
msg(
'colon-separator' )->inContentLanguage()->text() . $text;
209 return [ $final, $list, $text ];
215 return $this->mParams[
'size'] ?? 45;
219 # HTMLSelectField forces $value to be one of the options in the select
220 # field, which is not useful here. But we do want the validation further up
222 $p = parent::validate( $value[1], $alldata );
228 if ( isset( $this->mParams[
'required'] )
229 && $this->mParams[
'required'] !==
false
232 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()
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...