16 private const FIELD_CLASS =
'mw-htmlform-select-and-other-field';
18 private $mFlatOptions;
25 if ( array_key_exists(
'other', $params ) ) {
27 } elseif ( array_key_exists(
'other-message', $params ) ) {
28 $params[
'other'] = $this->
getMessage( $params[
'other-message'] )->plain();
30 $params[
'other'] = $this->
msg(
'htmlform-selectorother-other' )->plain();
33 parent::__construct( $params );
37 throw new MWException(
'HTMLSelectAndOtherField called without any options' );
39 if ( !in_array(
'other', $this->mOptions,
true ) ) {
47 $select = parent::getInputHTML( $value[1] );
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 );
73 'class' => self::FIELD_CLASS
75 if ( $this->mClass !==
'' ) {
78 return Html::rawElement(
81 "$select<br />\n$textbox"
86 return [
'mediawiki.widgets.SelectWithInputWidget' ];
90 $this->mParent->getOutput()->addModuleStyles(
'mediawiki.widgets.SelectWithInputWidget.styles' );
94 'name' => $this->mName .
'-other',
107 $textAttribs += OOUI\Element::configFromHtmlAttributes(
112 $dropdownInputAttribs = [
115 'value' => $value[1],
123 $dropdownInputAttribs += OOUI\Element::configFromHtmlAttributes(
128 if ( isset( $this->mParams[
'disabled' ] ) && $this->mParams[
'disabled' ] ) {
132 $inputClasses = [ self::FIELD_CLASS ];
133 if ( $this->mClass !==
'' ) {
134 $inputClasses = array_merge( $inputClasses, explode(
' ', $this->mClass ) );
138 'disabled' => $disabled,
139 'textinput' => $textAttribs,
140 'dropdowninput' => $dropdownInputAttribs,
142 'required' => $this->mParams[
'required' ] ??
false,
143 'classes' => $inputClasses,
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...