40 'require-match' =>
false,
43 parent::__construct( $params );
45 if ( array_key_exists(
'autocomplete-data-messages', $this->mParams ) ) {
46 foreach ( $this->mParams[
'autocomplete-data-messages'] as $key => $value ) {
47 $key = $this->
msg( $key )->plain();
48 $this->autocompleteData[$key] = strval( $value );
50 } elseif ( array_key_exists(
'autocomplete-data', $this->mParams ) ) {
51 foreach ( $this->mParams[
'autocomplete-data'] as $key => $value ) {
52 $this->autocompleteData[$key] = strval( $value );
55 if ( !is_array( $this->autocompleteData ) || !$this->autocompleteData ) {
56 throw new InvalidArgumentException(
'HTMLAutoCompleteSelectField called without any autocompletions' );
60 if ( $this->mOptions && !in_array(
'other', $this->mOptions,
true ) ) {
61 if ( isset( $params[
'other-message'] ) ) {
62 $msg = $this->
getMessage( $params[
'other-message'] )->text();
63 } elseif ( isset( $params[
'other'] ) ) {
64 $msg = $params[
'other'];
66 $msg =
wfMessage(
'htmlform-selectorother-other' )->text();
68 $this->mOptions[$msg] =
'other';
73 if ( $request->getCheck( $this->mName ) ) {
74 $val = $request->getText( $this->mName .
'-select',
'other' );
76 if ( $val ===
'other' ) {
77 $val = $request->getText( $this->mName );
78 if ( isset( $this->autocompleteData[$val] ) ) {
79 $val = $this->autocompleteData[$val];
90 $p = parent::validate( $value, $alldata );
98 if ( in_array( strval( $value ), $validOptions,
true ) ) {
100 } elseif ( in_array( strval( $value ), $this->autocompleteData,
true ) ) {
102 } elseif ( $this->mParams[
'require-match'] ) {
103 return $this->
msg(
'htmlform-select-badoption' );
113 'data-autocomplete' => FormatJson::encode( array_keys( $this->autocompleteData ) ),
114 ] + parent::getAttributes( $list );
117 $attribs[
'data-cond-state'] = FormatJson::encode( [
118 'hide' => [
'!==', $this->mName .
'-select',
'other' ],
127 $classes = (array)$this->mClass;
129 $valInSelect =
false;
133 if ( $value !==
false ) {
134 $value = strval( $value );
135 $valInSelect = in_array(
140 $selected = $valInSelect ? $value :
'other';
141 $select =
new XmlSelect( $this->mName .
'-select', $this->mID .
'-select', $selected );
144 if ( !empty( $this->mParams[
'disabled'] ) ) {
145 $select->setAttribute(
'disabled',
'disabled' );
148 if ( isset( $this->mParams[
'tabindex'] ) ) {
149 $select->setAttribute(
'tabindex', $this->mParams[
'tabindex'] );
152 $ret = $select->getHTML() .
"<br />\n";
154 $classes[] =
'mw-htmlform-hide-if';
157 if ( $valInSelect ) {
160 $key = array_search( strval( $value ), $this->autocompleteData,
true );
161 if ( $key !==
false ) {
166 $classes[] =
'mw-htmlform-autocomplete';
167 $this->mClass = implode(
' ', $classes );
168 $ret .= parent::getInputHTML( $valInSelect ?
'' : $value );
169 $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.