Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
HTMLComboboxField
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 4
56
0.00% covered (danger)
0.00%
0 / 1
 getAttributes
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 getInputHTML
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getInputOOUI
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
20
 shouldInfuseOOUI
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\HTMLForm\Field;
4
5use MediaWiki\Xml\XmlSelect;
6
7/**
8 * A combo box field.
9 *
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).
12 *
13 * When JavaScript is not supported or enabled, it uses HTML5 `<datalist>` element.
14 *
15 * Besides the parameters recognized by HTMLTextField, the following are
16 * recognized:
17 *   options-messages - As for HTMLSelectField
18 *   options - As for HTMLSelectField
19 *   options-message - As for HTMLSelectField
20 *
21 * @stable to extend
22 */
23class HTMLComboboxField extends HTMLTextField {
24    // FIXME Ewww, this shouldn't be adding any attributes not requested in $list :(
25    public function getAttributes( array $list ) {
26        $attribs = [
27            'type' => 'text',
28            'list' => $this->mName . '-datalist',
29        ] + parent::getAttributes( $list );
30
31        return $attribs;
32    }
33
34    public function getInputHTML( $value ) {
35        $datalist = new XmlSelect( false, $this->mName . '-datalist' );
36        $datalist->setTagName( 'datalist' );
37        $datalist->addOptions( $this->getOptions() );
38
39        return parent::getInputHTML( $value ) . $datalist->getHTML();
40    }
41
42    public function getInputOOUI( $value ) {
43        $disabled = false;
44        $allowedParams = [ 'tabindex' ];
45        $attribs = \OOUI\Element::configFromHtmlAttributes(
46            $this->getAttributes( $allowedParams )
47        );
48
49        if ( $this->mClass !== '' ) {
50            $attribs['classes'] = [ $this->mClass ];
51        }
52
53        if ( !empty( $this->mParams['disabled'] ) ) {
54            $disabled = true;
55        }
56
57        if ( $this->mPlaceholder !== '' ) {
58            $attribs['placeholder'] = $this->mPlaceholder;
59        }
60
61        return new \OOUI\ComboBoxInputWidget( [
62            'name' => $this->mName,
63            'id' => $this->mID,
64            'options' => $this->getOptionsOOUI(),
65            'value' => strval( $value ),
66            'disabled' => $disabled,
67        ] + $attribs );
68    }
69
70    protected function shouldInfuseOOUI() {
71        return true;
72    }
73}
74
75/** @deprecated class alias since 1.42 */
76class_alias( HTMLComboboxField::class, 'HTMLComboboxField' );