6use InvalidArgumentException;
47 'require-match' =>
false,
52 if ( array_key_exists(
'autocomplete-data-messages', $this->mParams ) ) {
53 foreach ( $this->mParams[
'autocomplete-data-messages'] as $key => $value ) {
54 $key = $this->
msg( $key )->plain();
55 $this->autocompleteData[$key] = strval( $value );
57 } elseif ( array_key_exists(
'autocomplete-data', $this->mParams ) ) {
58 foreach ( $this->mParams[
'autocomplete-data'] as $key => $value ) {
59 $this->autocompleteData[$key] = strval( $value );
62 if ( !is_array( $this->autocompleteData ) || !$this->autocompleteData ) {
63 throw new InvalidArgumentException(
'HTMLAutoCompleteSelectField called without any autocompletions' );
67 if ( $this->mOptions && !in_array(
'other', $this->mOptions,
true ) ) {
68 if ( isset(
$params[
'other-message'] ) ) {
70 } elseif ( isset(
$params[
'other'] ) ) {
73 $msg =
wfMessage(
'htmlform-selectorother-other' )->text();
75 $this->mOptions[$msg] =
'other';
80 if ( $request->getCheck( $this->mName ) ) {
81 $val = $request->getText( $this->mName .
'-select',
'other' );
83 if ( $val ===
'other' ) {
84 $val = $request->getText( $this->mName );
85 if ( isset( $this->autocompleteData[$val] ) ) {
86 $val = $this->autocompleteData[$val];
97 $p = parent::validate( $value, $alldata );
106 in_array( strval( $value ), $validOptions,
true ) ||
107 in_array( strval( $value ), $this->autocompleteData,
true )
110 } elseif ( $this->mParams[
'require-match'] ) {
111 return $this->
msg(
'htmlform-select-badoption' );
121 'data-autocomplete' => FormatJson::encode( array_keys( $this->autocompleteData ) ),
122 ] + parent::getAttributes( $list );
125 $attribs[
'data-cond-state'] = FormatJson::encode( [
126 'hide' => [
'!==', $this->mName .
'-select',
'other' ],
135 $classes = (array)$this->mClass;
137 $valInSelect =
false;
141 if ( $value !==
false ) {
142 $value = strval( $value );
143 $valInSelect = in_array(
148 $selected = $valInSelect ? $value :
'other';
149 $select =
new XmlSelect( $this->mName .
'-select', $this->mID .
'-select', $selected );
152 if ( !empty( $this->mParams[
'disabled'] ) ) {
153 $select->setAttribute(
'disabled',
'disabled' );
156 if ( isset( $this->mParams[
'tabindex'] ) ) {
157 $select->setAttribute(
'tabindex', $this->mParams[
'tabindex'] );
160 $ret = $select->getHTML() .
"<br />\n";
162 $classes[] =
'mw-htmlform-hide-if';
165 if ( $valInSelect ) {
168 $key = array_search( strval( $value ), $this->autocompleteData,
true );
169 if ( $key !==
false ) {
174 $classes[] =
'mw-htmlform-autocomplete';
175 $this->mClass = implode(
' ', $classes );
176 $ret .= parent::getInputHTML( $valInSelect ?
'' : $value );
177 $this->mClass = $oldClass;
194class_alias( HTMLAutoCompleteSelectField::class,
'HTMLAutoCompleteSelectField' );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
array $params
The job parameters.
Class for generating HTML <select> or <datalist> elements.