Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / htmlform / fields / HTMLComboboxField.php
blob27f1ccb63c3f1ed96b0d2c8cd88a7530304c7b3b
1 <?php
3 namespace MediaWiki\HTMLForm\Field;
5 use MediaWiki\Xml\XmlSelect;
7 /**
8 * A combo box field.
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
16 * recognized:
17 * options-messages - As for HTMLSelectField
18 * options - As for HTMLSelectField
19 * options-message - As for HTMLSelectField
21 * @stable to extend
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 ) {
26 $attribs = [
27 'type' => 'text',
28 'list' => $this->mName . '-datalist',
29 ] + parent::getAttributes( $list );
31 return $attribs;
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 ) {
43 $disabled = false;
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'] ) ) {
54 $disabled = true;
57 if ( $this->mPlaceholder !== '' ) {
58 $attribs['placeholder'] = $this->mPlaceholder;
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 );
70 protected function shouldInfuseOOUI() {
71 return true;
75 /** @deprecated class alias since 1.42 */
76 class_alias( HTMLComboboxField::class, 'HTMLComboboxField' );