2013-11-19 12:55:50 +00:00
|
|
|
<?php
|
2013-11-19 13:08:16 +00:00
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
/**
|
|
|
|
|
* A select dropdown field. Basically a wrapper for Xmlselect class
|
|
|
|
|
*/
|
|
|
|
|
class HTMLSelectField extends HTMLFormField {
|
|
|
|
|
function validate( $value, $alldata ) {
|
|
|
|
|
$p = parent::validate( $value, $alldata );
|
|
|
|
|
|
|
|
|
|
if ( $p !== true ) {
|
|
|
|
|
return $p;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-18 20:28:06 +00:00
|
|
|
$validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
|
2013-11-19 12:55:50 +00:00
|
|
|
|
2014-03-05 20:15:41 +00:00
|
|
|
if ( in_array( strval( $value ), $validOptions, true ) ) {
|
2013-11-19 12:55:50 +00:00
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return $this->msg( 'htmlform-select-badoption' )->parse();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getInputHTML( $value ) {
|
|
|
|
|
$select = new XmlSelect( $this->mName, $this->mID, strval( $value ) );
|
|
|
|
|
|
2013-11-19 13:08:16 +00:00
|
|
|
if ( !empty( $this->mParams['disabled'] ) ) {
|
2013-11-19 12:55:50 +00:00
|
|
|
$select->setAttribute( 'disabled', 'disabled' );
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-06 18:51:17 +00:00
|
|
|
$allowedParams = array( 'tabindex', 'size' );
|
|
|
|
|
$customParams = $this->getAttributes( $allowedParams );
|
2014-07-19 21:12:10 +00:00
|
|
|
foreach ( $customParams as $name => $value ) {
|
2014-07-06 18:51:17 +00:00
|
|
|
$select->setAttribute( $name, $value );
|
2013-05-02 18:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
if ( $this->mClass !== '' ) {
|
|
|
|
|
$select->setAttribute( 'class', $this->mClass );
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-18 20:28:06 +00:00
|
|
|
$select->addOptions( $this->getOptions() );
|
2013-11-19 12:55:50 +00:00
|
|
|
|
|
|
|
|
return $select->getHTML();
|
|
|
|
|
}
|
2013-11-19 13:08:16 +00:00
|
|
|
}
|