MediaWiki  master
HTMLComboboxField.php
Go to the documentation of this file.
1 <?php
2 
20  // FIXME Ewww, this shouldn't be adding any attributes not requested in $list :(
21  public function getAttributes( array $list ) {
22  $attribs = [
23  'type' => 'text',
24  'list' => $this->mName . '-datalist',
25  ] + parent::getAttributes( $list );
26 
27  return $attribs;
28  }
29 
30  public function getInputHTML( $value ) {
31  $datalist = new XmlSelect( false, $this->mName . '-datalist' );
32  $datalist->setTagName( 'datalist' );
33  $datalist->addOptions( $this->getOptions() );
34 
35  return parent::getInputHTML( $value ) . $datalist->getHTML();
36  }
37 
38  public function getInputOOUI( $value ) {
39  $disabled = false;
40  $allowedParams = [ 'tabindex' ];
41  $attribs = OOUI\Element::configFromHtmlAttributes(
42  $this->getAttributes( $allowedParams )
43  );
44 
45  if ( $this->mClass !== '' ) {
46  $attribs['classes'] = [ $this->mClass ];
47  }
48 
49  if ( !empty( $this->mParams['disabled'] ) ) {
50  $disabled = true;
51  }
52 
53  return new OOUI\ComboBoxInputWidget( [
54  'name' => $this->mName,
55  'id' => $this->mID,
56  'options' => $this->getOptionsOOUI(),
57  'value' => strval( $value ),
58  'disabled' => $disabled,
59  ] + $attribs );
60  }
61 
62  protected function shouldInfuseOOUI() {
63  return true;
64  }
65 }
HTMLFormField\getOptions
getOptions()
Fetch the array of options from the field's parameters.
Definition: HTMLFormField.php:1095
HTMLComboboxField
A combo box field.
Definition: HTMLComboboxField.php:19
HTMLFormField\$mClass
$mClass
Definition: HTMLFormField.php:19
HTMLTextField
<input> field.
Definition: HTMLTextField.php:15
XmlSelect
Class for generating HTML <select> or <datalist> elements.
Definition: XmlSelect.php:26
HTMLComboboxField\getInputOOUI
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
Definition: HTMLComboboxField.php:38
HTMLComboboxField\shouldInfuseOOUI
shouldInfuseOOUI()
Whether the field should be automatically infused.
Definition: HTMLComboboxField.php:62
HTMLComboboxField\getInputHTML
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
Definition: HTMLComboboxField.php:30
HTMLComboboxField\getAttributes
getAttributes(array $list)
Returns the given attributes from the parameters Stable to override.
Definition: HTMLComboboxField.php:21
HTMLFormField\getOptionsOOUI
getOptionsOOUI()
Get options and make them into arrays suitable for OOUI.
Definition: HTMLFormField.php:1118