3 namespace MediaWiki\HTMLForm\Field
;
5 use MediaWiki\Xml\XmlSelect
;
10 * You can think of it as a dropdown select with the ability to add custom options,
11 * or as a text field with input suggestions (autocompletion).
13 * When JavaScript is not supported or enabled, it uses HTML5 `<datalist>` element.
15 * Besides the parameters recognized by HTMLTextField, the following are
17 * options-messages - As for HTMLSelectField
18 * options - As for HTMLSelectField
19 * options-message - As for HTMLSelectField
23 class HTMLComboboxField
extends HTMLTextField
{
24 // FIXME Ewww, this shouldn't be adding any attributes not requested in $list :(
25 public function getAttributes( array $list ) {
28 'list' => $this->mName
. '-datalist',
29 ] + parent
::getAttributes( $list );
34 public function getInputHTML( $value ) {
35 $datalist = new XmlSelect( false, $this->mName
. '-datalist' );
36 $datalist->setTagName( 'datalist' );
37 $datalist->addOptions( $this->getOptions() );
39 return parent
::getInputHTML( $value ) . $datalist->getHTML();
42 public function getInputOOUI( $value ) {
44 $allowedParams = [ 'tabindex' ];
45 $attribs = \OOUI\Element
::configFromHtmlAttributes(
46 $this->getAttributes( $allowedParams )
49 if ( $this->mClass
!== '' ) {
50 $attribs['classes'] = [ $this->mClass
];
53 if ( !empty( $this->mParams
['disabled'] ) ) {
57 if ( $this->mPlaceholder
!== '' ) {
58 $attribs['placeholder'] = $this->mPlaceholder
;
61 return new \OOUI\
ComboBoxInputWidget( [
62 'name' => $this->mName
,
64 'options' => $this->getOptionsOOUI(),
65 'value' => strval( $value ),
66 'disabled' => $disabled,
70 protected function shouldInfuseOOUI() {
75 /** @deprecated class alias since 1.42 */
76 class_alias( HTMLComboboxField
::class, 'HTMLComboboxField' );