Added a separate error message for mkdir failures
[lhc/web/wiklou.git] / includes / htmlform / HTMLSelectField.php
1 <?php
2
3 /**
4 * A select dropdown field. Basically a wrapper for Xmlselect class
5 */
6 class HTMLSelectField extends HTMLFormField {
7 function validate( $value, $alldata ) {
8 $p = parent::validate( $value, $alldata );
9
10 if ( $p !== true ) {
11 return $p;
12 }
13
14 $validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
15
16 if ( in_array( strval( $value ), $validOptions, true ) ) {
17 return true;
18 } else {
19 return $this->msg( 'htmlform-select-badoption' )->parse();
20 }
21 }
22
23 function getInputHTML( $value ) {
24 $select = new XmlSelect( $this->mName, $this->mID, strval( $value ) );
25
26 if ( !empty( $this->mParams['disabled'] ) ) {
27 $select->setAttribute( 'disabled', 'disabled' );
28 }
29
30 $allowedParams = array( 'tabindex', 'size' );
31 $customParams = $this->getAttributes( $allowedParams );
32 foreach ( $customParams as $name => $value ) {
33 $select->setAttribute( $name, $value );
34 }
35
36 if ( $this->mClass !== '' ) {
37 $select->setAttribute( 'class', $this->mClass );
38 }
39
40 $select->addOptions( $this->getOptions() );
41
42 return $select->getHTML();
43 }
44
45 function getInputOOUI( $value ) {
46 $disabled = false;
47 $allowedParams = array( 'tabindex' );
48 $attribs = $this->getAttributes( $allowedParams, array( 'tabindex' => 'tabIndex' ) );
49
50 if ( $this->mClass !== '' ) {
51 $attribs['classes'] = array( $this->mClass );
52 }
53
54 if ( !empty( $this->mParams['disabled'] ) ) {
55 $disabled = true;
56 }
57
58 return new OOUI\DropdownInputWidget( array(
59 'name' => $this->mName,
60 'id' => $this->mID,
61 'options' => $this->getOptionsOOUI(),
62 'value' => strval( $value ),
63 'disabled' => $disabled,
64 ) + $attribs );
65 }
66 }