43 'require-match' =>
false,
48 array_key_exists(
'autocomplete', $params )
49 && !array_key_exists(
'autocomplete-data', $params )
51 $params[
'autocomplete-data'] = $params[
'autocomplete'];
52 unset( $params[
'autocomplete'] );
55 array_key_exists(
'autocomplete-messages', $params )
56 && !array_key_exists(
'autocomplete-data-messages', $params )
58 $params[
'autocomplete-data-messages'] = $params[
'autocomplete-messages'];
59 unset( $params[
'autocomplete-messages'] );
62 parent::__construct( $params );
64 if ( array_key_exists(
'autocomplete-data-messages', $this->mParams ) ) {
65 foreach ( $this->mParams[
'autocomplete-data-messages'] as $key => $value ) {
66 $key = $this->
msg( $key )->plain();
67 $this->autocompleteData[$key] = strval( $value );
69 } elseif ( array_key_exists(
'autocomplete-data', $this->mParams ) ) {
70 foreach ( $this->mParams[
'autocomplete-data'] as $key => $value ) {
71 $this->autocompleteData[$key] = strval( $value );
74 if ( !is_array( $this->autocompleteData ) || !$this->autocompleteData ) {
75 throw new MWException(
'HTMLAutoCompleteSelectField called without any autocompletions' );
79 if ( $this->mOptions && !in_array(
'other', $this->mOptions,
true ) ) {
80 if ( isset( $params[
'other-message'] ) ) {
81 $msg = $this->
getMessage( $params[
'other-message'] )->text();
82 } elseif ( isset( $params[
'other'] ) ) {
83 $msg = $params[
'other'];
85 $msg =
wfMessage(
'htmlform-selectorother-other' )->text();
87 $this->mOptions[$msg] =
'other';
92 if ( $request->getCheck( $this->mName ) ) {
93 $val = $request->getText( $this->mName .
'-select',
'other' );
95 if ( $val ===
'other' ) {
96 $val = $request->getText( $this->mName );
97 if ( isset( $this->autocompleteData[$val] ) ) {
98 $val = $this->autocompleteData[$val];
109 $p = parent::validate( $value, $alldata );
117 if ( in_array( strval( $value ), $validOptions,
true ) ) {
119 } elseif ( in_array( strval( $value ), $this->autocompleteData,
true ) ) {
121 } elseif ( $this->mParams[
'require-match'] ) {
122 return $this->
msg(
'htmlform-select-badoption' );
132 'data-autocomplete' => FormatJson::encode( array_keys( $this->autocompleteData ) ),
133 ] + parent::getAttributes( $list );
136 $attribs[
'data-hide-if'] = FormatJson::encode(
137 [
'!==', $this->mName .
'-select',
'other' ]
146 $this->mClass = (array)$this->mClass;
148 $valInSelect =
false;
152 if ( $value !==
false ) {
153 $value = strval( $value );
154 $valInSelect = in_array(
159 $selected = $valInSelect ? $value :
'other';
160 $select =
new XmlSelect( $this->mName .
'-select', $this->mID .
'-select', $selected );
162 $select->setAttribute(
'class',
'mw-htmlform-select-or-other' );
164 if ( !empty( $this->mParams[
'disabled'] ) ) {
165 $select->setAttribute(
'disabled',
'disabled' );
168 if ( isset( $this->mParams[
'tabindex'] ) ) {
169 $select->setAttribute(
'tabindex', $this->mParams[
'tabindex'] );
172 $ret = $select->getHTML() .
"<br />\n";
174 $this->mClass[] =
'mw-htmlform-hide-if';
177 if ( $valInSelect ) {
180 $key = array_search( strval( $value ), $this->autocompleteData,
true );
181 if ( $key !==
false ) {
186 $this->mClass[] =
'mw-htmlform-autocomplete';
187 $ret .= parent::getInputHTML( $valInSelect ?
'' : $value );
188 $this->mClass = $oldClass;
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Text field for selecting a value from a large list of possible values, with auto-completion and optio...
__construct( $params)
Stable to call.
getInputOOUI( $value)
Get the OOUI version of this input.
getAttributes(array $list)
Returns the given attributes from the parameters Stable to override.
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
loadDataFromRequest( $request)
Get the value that this input has been set to from a posted form, or the input's default value if it ...
Class for generating HTML <select> or <datalist> elements.