08be43550088f429587282c69de7063176eacb13
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 if ( isset( $this->mParams
['tabindex'] ) ) {
51 $select->setAttribute( 'tabindex', $this->mParams
['tabindex'] );
52 $tbAttribs['tabindex'] = $this->mParams
['tabindex'];
55 $select = $select->getHTML();
57 if ( isset( $this->mParams
['maxlength'] ) ) {
58 $tbAttribs['maxlength'] = $this->mParams
['maxlength'];
61 if ( $this->mClass
!== '' ) {
62 $tbAttribs['class'] = $this->mClass
;
65 $textbox = Html
::input( $this->mName
. '-other', $valInSelect ?
'' : $value, 'text', $tbAttribs );
67 return "$select<br />\n$textbox";
71 * @param $request WebRequest
75 function loadDataFromRequest( $request ) {
76 if ( $request->getCheck( $this->mName
) ) {
77 $val = $request->getText( $this->mName
);
79 if ( $val == 'other' ) {
80 $val = $request->getText( $this->mName
. '-other' );
85 return $this->getDefault();