Merge "Import: Handle uploads with sha1 starting with 0 properly"
[mediawiki.git] / includes / htmlform / HTMLComboboxField.php
blobe5679bbf067f7b84bd2eb676a06d060b86c0fbd9
1 <?php
3 /**
4 * A combo box field.
6 * You can think of it as a dropdown select with the ability to add custom options,
7 * or as a text field with input suggestions (autocompletion).
9 * When JavaScript is not supported or enabled, it uses HTML5 `<datalist>` element.
11 * Besides the parameters recognized by HTMLTextField, the following are
12 * recognized:
13 * options-messages - As for HTMLSelectField
14 * options - As for HTMLSelectField
15 * options-message - As for HTMLSelectField
17 class HTMLComboboxField extends HTMLTextField {
18 // FIXME Ewww, this shouldn't be adding any attributes not requested in $list :(
19 public function getAttributes( array $list, array $mappings = null ) {
20 $attribs = array(
21 'type' => 'text',
22 'list' => $this->mName . '-datalist',
23 ) + parent::getAttributes( $list, $mappings );
25 return $attribs;
28 function getInputHTML( $value ) {
29 $datalist = new XmlSelect( false, $this->mName . '-datalist' );
30 $datalist->setTagName( 'datalist' );
31 $datalist->addOptions( $this->getOptions() );
33 return parent::getInputHTML( $value ) . $datalist->getHTML();
36 function getInputOOUI( $value ) {
37 $disabled = false;
38 $allowedParams = array( 'tabindex' );
39 $attribs = $this->getAttributes( $allowedParams, array( 'tabindex' => 'tabIndex' ) );
41 if ( $this->mClass !== '' ) {
42 $attribs['classes'] = array( $this->mClass );
45 if ( !empty( $this->mParams['disabled'] ) ) {
46 $disabled = true;
49 return new OOUI\ComboBoxInputWidget( array(
50 'name' => $this->mName,
51 'id' => $this->mID,
52 'options' => $this->getOptionsOOUI(),
53 'value' => strval( $value ),
54 'disabled' => $disabled,
55 ) + $attribs );