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  if ( $this->mPlaceholder !== '' ) {
54  $attribs['placeholder'] = $this->mPlaceholder;
55  }
56 
57  return new OOUI\ComboBoxInputWidget( [
58  'name' => $this->mName,
59  'id' => $this->mID,
60  'options' => $this->getOptionsOOUI(),
61  'value' => strval( $value ),
62  'disabled' => $disabled,
63  ] + $attribs );
64  }
65 
66  protected function shouldInfuseOOUI() {
67  return true;
68  }
69 }
A combo box field.
shouldInfuseOOUI()
Whether the field should be automatically infused.
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
getAttributes(array $list)
Returns the given attributes from the parameters.
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
getOptions()
Fetch the array of options from the field's parameters.
getOptionsOOUI()
Get options and make them into arrays suitable for OOUI.
<input> field.
Class for generating HTML <select> or <datalist> elements.
Definition: XmlSelect.php:26