4 * Select dropdown field, with an additional "other" textbox.
6 class HTMLSelectOrOtherField
extends HTMLTextField
{
7 function __construct( $params ) {
8 parent
::__construct( $params );
10 if ( !in_array( 'other', $this->mOptions
, true ) ) {
12 isset( $params['other'] )
14 : wfMessage( 'htmlform-selectorother-other' )->text();
15 $this->mOptions
[$msg] = 'other';
20 function getInputHTML( $value ) {
23 if ( $value !== false ) {
24 $valInSelect = in_array( $value, HTMLFormField
::flattenOptions( $this->getOptions() ) );
27 $selected = $valInSelect ?
$value : 'other';
29 $select = new XmlSelect( $this->mName
, $this->mID
, $selected );
30 $select->addOptions( $this->getOptions() );
32 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
34 $tbAttribs = array( 'id' => $this->mID
. '-other', 'size' => $this->getSize() );
36 if ( !empty( $this->mParams
['disabled'] ) ) {
37 $select->setAttribute( 'disabled', 'disabled' );
38 $tbAttribs['disabled'] = 'disabled';
41 if ( isset( $this->mParams
['tabindex'] ) ) {
42 $select->setAttribute( 'tabindex', $this->mParams
['tabindex'] );
43 $tbAttribs['tabindex'] = $this->mParams
['tabindex'];
46 $select = $select->getHTML();
48 if ( isset( $this->mParams
['maxlength'] ) ) {
49 $tbAttribs['maxlength'] = $this->mParams
['maxlength'];
52 if ( $this->mClass
!== '' ) {
53 $tbAttribs['class'] = $this->mClass
;
56 $textbox = Html
::input( $this->mName
. '-other', $valInSelect ?
'' : $value, 'text', $tbAttribs );
58 return "$select<br />\n$textbox";
62 * @param $request WebRequest
66 function loadDataFromRequest( $request ) {
67 if ( $request->getCheck( $this->mName
) ) {
68 $val = $request->getText( $this->mName
);
70 if ( $val == 'other' ) {
71 $val = $request->getText( $this->mName
. '-other' );
76 return $this->getDefault();