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 $value = strval( $value );
25 $valInSelect = in_array(
26 $value, HTMLFormField
::flattenOptions( $this->getOptions() ), true
30 $selected = $valInSelect ?
$value : 'other';
32 $select = new XmlSelect( $this->mName
, $this->mID
, $selected );
33 $select->addOptions( $this->getOptions() );
35 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
37 $tbAttribs = array( 'id' => $this->mID
. '-other', 'size' => $this->getSize() );
39 if ( !empty( $this->mParams
['disabled'] ) ) {
40 $select->setAttribute( 'disabled', 'disabled' );
41 $tbAttribs['disabled'] = 'disabled';
44 if ( isset( $this->mParams
['tabindex'] ) ) {
45 $select->setAttribute( 'tabindex', $this->mParams
['tabindex'] );
46 $tbAttribs['tabindex'] = $this->mParams
['tabindex'];
49 $select = $select->getHTML();
51 if ( isset( $this->mParams
['maxlength'] ) ) {
52 $tbAttribs['maxlength'] = $this->mParams
['maxlength'];
55 if ( $this->mClass
!== '' ) {
56 $tbAttribs['class'] = $this->mClass
;
59 $textbox = Html
::input( $this->mName
. '-other', $valInSelect ?
'' : $value, 'text', $tbAttribs );
61 return "$select<br />\n$textbox";
65 * @param WebRequest $request
69 function loadDataFromRequest( $request ) {
70 if ( $request->getCheck( $this->mName
) ) {
71 $val = $request->getText( $this->mName
);
73 if ( $val === 'other' ) {
74 $val = $request->getText( $this->mName
. '-other' );
79 return $this->getDefault();