44 'require-match' =>
false,
49 array_key_exists(
'autocomplete', $params )
50 && !array_key_exists(
'autocomplete-data', $params )
52 $params[
'autocomplete-data'] = $params[
'autocomplete'];
53 unset( $params[
'autocomplete'] );
56 array_key_exists(
'autocomplete-messages', $params )
57 && !array_key_exists(
'autocomplete-data-messages', $params )
59 $params[
'autocomplete-data-messages'] = $params[
'autocomplete-messages'];
60 unset( $params[
'autocomplete-messages'] );
63 parent::__construct( $params );
65 if ( array_key_exists(
'autocomplete-data-messages', $this->mParams ) ) {
66 foreach ( $this->mParams[
'autocomplete-data-messages'] as $key => $value ) {
67 $key = $this->
msg( $key )->plain();
68 $this->autocompleteData[$key] = strval( $value );
70 } elseif ( array_key_exists(
'autocomplete-data', $this->mParams ) ) {
71 foreach ( $this->mParams[
'autocomplete-data'] as $key => $value ) {
72 $this->autocompleteData[$key] = strval( $value );
75 if ( !is_array( $this->autocompleteData ) || !$this->autocompleteData ) {
76 throw new MWException(
'HTMLAutoCompleteSelectField called without any autocompletions' );
80 if ( $this->mOptions && !in_array(
'other', $this->mOptions,
true ) ) {
81 if ( isset( $params[
'other-message'] ) ) {
82 $msg = $this->
getMessage( $params[
'other-message'] )->text();
83 } elseif ( isset( $params[
'other'] ) ) {
84 $msg = $params[
'other'];
86 $msg =
wfMessage(
'htmlform-selectorother-other' )->text();
88 $this->mOptions[$msg] =
'other';
93 if ( $request->getCheck( $this->mName ) ) {
94 $val = $request->getText( $this->mName .
'-select',
'other' );
96 if ( $val ===
'other' ) {
97 $val = $request->getText( $this->mName );
98 if ( isset( $this->autocompleteData[$val] ) ) {
99 $val = $this->autocompleteData[$val];
110 $p = parent::validate( $value, $alldata );
118 if ( in_array( strval( $value ), $validOptions,
true ) ) {
120 } elseif ( in_array( strval( $value ), $this->autocompleteData,
true ) ) {
122 } elseif ( $this->mParams[
'require-match'] ) {
123 return $this->
msg(
'htmlform-select-badoption' );
133 'data-autocomplete' => FormatJson::encode( array_keys( $this->autocompleteData ) ),
134 ] + parent::getAttributes( $list );
137 $attribs[
'data-hide-if'] = FormatJson::encode(
138 [
'!==', $this->mName .
'-select',
'other' ]
147 $this->mClass = (array)$this->mClass;
149 $valInSelect =
false;
153 if ( $value !==
false ) {
154 $value = strval( $value );
155 $valInSelect = in_array(
160 $selected = $valInSelect ? $value :
'other';
161 $select =
new XmlSelect( $this->mName .
'-select', $this->mID .
'-select', $selected );
163 $select->setAttribute(
'class',
'mw-htmlform-select-or-other' );
165 if ( !empty( $this->mParams[
'disabled'] ) ) {
166 $select->setAttribute(
'disabled',
'disabled' );
169 if ( isset( $this->mParams[
'tabindex'] ) ) {
170 $select->setAttribute(
'tabindex', $this->mParams[
'tabindex'] );
173 $ret = $select->getHTML() .
"<br />\n";
175 $this->mClass[] =
'mw-htmlform-hide-if';
178 if ( $valInSelect ) {
181 $key = array_search( strval( $value ), $this->autocompleteData,
true );
182 if ( $key !==
false ) {
187 $this->mClass[] =
'mw-htmlform-autocomplete';
188 $ret .= parent::getInputHTML( $valInSelect ?
'' : $value );
189 $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...
getInputOOUI( $value)
Get the OOUI version of this input.
getAttributes(array $list)
Returns the given attributes from the parameters.
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.