4 * Select dropdown field, with an additional "other" textbox.
6 class HTMLSelectOrOtherField
extends HTMLTextField
{
7 function __construct( $params ) {
8 if ( !in_array( 'other', $params['options'], true ) ) {
10 isset( $params['other'] )
12 : wfMessage( 'htmlform-selectorother-other' )->text();
13 $params['options'][$msg] = 'other';
16 parent
::__construct( $params );
19 static function forceToStringRecursive( $array ) {
20 if ( is_array( $array ) ) {
21 return array_map( array( __CLASS__
, 'forceToStringRecursive' ), $array );
23 return strval( $array );
27 function getInputHTML( $value ) {
30 if ( $value !== false ) {
31 $valInSelect = in_array( $value, HTMLFormField
::flattenOptions( $this->mParams
['options'] ) );
34 $selected = $valInSelect ?
$value : 'other';
36 $opts = self
::forceToStringRecursive( $this->mParams
['options'] );
38 $select = new XmlSelect( $this->mName
, $this->mID
, $selected );
39 $select->addOptions( $opts );
41 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
43 $tbAttribs = array( 'id' => $this->mID
. '-other', 'size' => $this->getSize() );
45 if ( !empty( $this->mParams
['disabled'] ) ) {
46 $select->setAttribute( 'disabled', 'disabled' );
47 $tbAttribs['disabled'] = 'disabled';
50 $select = $select->getHTML();
52 if ( isset( $this->mParams
['maxlength'] ) ) {
53 $tbAttribs['maxlength'] = $this->mParams
['maxlength'];
56 if ( $this->mClass
!== '' ) {
57 $tbAttribs['class'] = $this->mClass
;
60 $textbox = Html
::input( $this->mName
. '-other', $valInSelect ?
'' : $value, 'text', $tbAttribs );
62 return "$select<br />\n$textbox";
66 * @param $request WebRequest
70 function loadDataFromRequest( $request ) {
71 if ( $request->getCheck( $this->mName
) ) {
72 $val = $request->getText( $this->mName
);
74 if ( $val == 'other' ) {
75 $val = $request->getText( $this->mName
. '-other' );
80 return $this->getDefault();