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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-19 13:08:16 +00:00
|
|
|
$validOptions = HTMLFormField::flattenOptions( $this->mParams['options'] );
|
2013-11-19 12:55:50 +00:00
|
|
|
|
|
|
|
|
if ( in_array( $value, $validOptions ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return $this->msg( 'htmlform-select-badoption' )->parse();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getInputHTML( $value ) {
|
|
|
|
|
$select = new XmlSelect( $this->mName, $this->mID, strval( $value ) );
|
|
|
|
|
|
|
|
|
|
# If one of the options' 'name' is int(0), it is automatically selected.
|
|
|
|
|
# because PHP sucks and thinks int(0) == 'some string'.
|
|
|
|
|
# Working around this by forcing all of them to strings.
|
2013-11-19 13:08:16 +00:00
|
|
|
foreach ( $this->mParams['options'] as &$opt ) {
|
2013-11-19 12:55:50 +00:00
|
|
|
if ( is_int( $opt ) ) {
|
|
|
|
|
$opt = strval( $opt );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
unset( $opt ); # PHP keeps $opt around as a reference, which is a bit scary
|
|
|
|
|
|
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' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->mClass !== '' ) {
|
|
|
|
|
$select->setAttribute( 'class', $this->mClass );
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-19 13:08:16 +00:00
|
|
|
$select->addOptions( $this->mParams['options'] );
|
2013-11-19 12:55:50 +00:00
|
|
|
|
|
|
|
|
return $select->getHTML();
|
|
|
|
|
}
|
2013-11-19 13:08:16 +00:00
|
|
|
}
|