3 namespace MediaWiki\HTMLForm\Field
;
5 use MediaWiki\HTMLForm\HTMLFormField
;
6 use MediaWiki\Xml\XmlSelect
;
9 * A select dropdown field. Basically a wrapper for Xmlselect class
13 class HTMLSelectField
extends HTMLFormField
{
19 public function validate( $value, $alldata ) {
20 $p = parent
::validate( $value, $alldata );
26 $validOptions = HTMLFormField
::flattenOptions( $this->getOptions() );
28 if ( in_array( strval( $value ), $validOptions, true ) ) {
31 return $this->msg( 'htmlform-select-badoption' );
39 public function getInputHTML( $value ) {
40 $select = new XmlSelect( $this->mName
, $this->mID
, strval( $value ) );
42 if ( !empty( $this->mParams
['disabled'] ) ) {
43 $select->setAttribute( 'disabled', 'disabled' );
46 $allowedParams = [ 'tabindex', 'size' ];
47 $customParams = $this->getAttributes( $allowedParams );
48 foreach ( $customParams as $name => $value ) {
49 $select->setAttribute( $name, $value );
52 if ( $this->mClass
!== '' ) {
53 $select->setAttribute( 'class', $this->mClass
);
56 $select->addOptions( $this->getOptions() );
58 return $select->getHTML();
65 public function getInputOOUI( $value ) {
67 $allowedParams = [ 'tabindex' ];
68 $attribs = \OOUI\Element
::configFromHtmlAttributes(
69 $this->getAttributes( $allowedParams )
72 if ( $this->mClass
!== '' ) {
73 $attribs['classes'] = [ $this->mClass
];
76 if ( !empty( $this->mParams
['disabled'] ) ) {
80 return new \OOUI\
DropdownInputWidget( [
81 'name' => $this->mName
,
83 'options' => $this->getOptionsOOUI(),
84 'value' => strval( $value ),
85 'disabled' => $disabled,
89 public function getInputCodex( $value, $hasErrors ) {
90 $select = new XmlSelect( $this->mName
, $this->mID
, strval( $value ) );
92 if ( !empty( $this->mParams
['disabled'] ) ) {
93 $select->setAttribute( 'disabled', 'disabled' );
96 $allowedParams = [ 'tabindex', 'size' ];
97 $customParams = $this->getAttributes( $allowedParams );
98 foreach ( $customParams as $name => $value ) {
99 $select->setAttribute( $name, $value );
102 // TODO: Add support for error class once it's implemented in the Codex CSS-only Select.
103 $selectClass = 'cdx-select';
104 $selectClass .= $this->mClass
!== '' ?
' ' . $this->mClass
: '';
105 $select->setAttribute( 'class', $selectClass );
107 $select->addOptions( $this->getOptions() );
109 return $select->getHTML();
114 * @stable to override
116 protected function shouldInfuseOOUI() {
121 /** @deprecated class alias since 1.42 */
122 class_alias( HTMLSelectField
::class, 'HTMLSelectField' );