MediaWiki master
HTMLComboboxField.php
Go to the documentation of this file.
1<?php
2
4
5use XmlSelect;
6
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
76class_alias( HTMLComboboxField::class, 'HTMLComboboxField' );
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
shouldInfuseOOUI()
Whether the field should be automatically infused.
getAttributes(array $list)
Returns the given attributes from the parameters.
getOptionsOOUI()
Get options and make them into arrays suitable for OOUI.
getOptions()
Fetch the array of options from the field's parameters.
Class for generating HTML <select> or <datalist> elements.
Definition XmlSelect.php:28