MediaWiki REL1_39
HTMLSelectField.php
Go to the documentation of this file.
1<?php
2
9
14 public function validate( $value, $alldata ) {
15 $p = parent::validate( $value, $alldata );
16
17 if ( $p !== true ) {
18 return $p;
19 }
20
21 $validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
22
23 if ( in_array( strval( $value ), $validOptions, true ) ) {
24 return true;
25 } else {
26 return $this->msg( 'htmlform-select-badoption' );
27 }
28 }
29
34 public function getInputHTML( $value ) {
35 $select = new XmlSelect( $this->mName, $this->mID, strval( $value ) );
36
37 if ( !empty( $this->mParams['disabled'] ) ) {
38 $select->setAttribute( 'disabled', 'disabled' );
39 }
40
41 $allowedParams = [ 'tabindex', 'size' ];
42 $customParams = $this->getAttributes( $allowedParams );
43 foreach ( $customParams as $name => $value ) {
44 $select->setAttribute( $name, $value );
45 }
46
47 if ( $this->mClass !== '' ) {
48 $select->setAttribute( 'class', $this->mClass );
49 }
50
51 $select->addOptions( $this->getOptions() );
52
53 return $select->getHTML();
54 }
55
60 public function getInputOOUI( $value ) {
61 $disabled = false;
62 $allowedParams = [ 'tabindex' ];
63 $attribs = OOUI\Element::configFromHtmlAttributes(
64 $this->getAttributes( $allowedParams )
65 );
66
67 if ( $this->mClass !== '' ) {
68 $attribs['classes'] = [ $this->mClass ];
69 }
70
71 if ( !empty( $this->mParams['disabled'] ) ) {
72 $disabled = true;
73 }
74
75 return new OOUI\DropdownInputWidget( [
76 'name' => $this->mName,
77 'id' => $this->mID,
78 'options' => $this->getOptionsOOUI(),
79 'value' => strval( $value ),
80 'disabled' => $disabled,
81 ] + $attribs );
82 }
83
88 protected function shouldInfuseOOUI() {
89 return true;
90 }
91}
The parent class to generate form fields.
static flattenOptions( $options)
flatten an array of options to a single array, for instance, a set of "<options>" inside "<optgroups>...
getOptions()
Fetch the array of options from the field's parameters.
msg( $key,... $params)
Get a translated interface message.
getAttributes(array $list)
Returns the given attributes from the parameters.
getOptionsOOUI()
Get options and make them into arrays suitable for OOUI.
A select dropdown field.
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.Don't forget to call pare...
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
shouldInfuseOOUI()
Whether the field should be automatically infused.Note that all OOUI HTMLForm fields are infusable (y...
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
Class for generating HTML <select> or <datalist> elements.
Definition XmlSelect.php:26