4 * Select dropdown field, with an additional "other" textbox.
6 * HTMLComboboxField implements the same functionality using a single form field
7 * and should be used instead.
9 class HTMLSelectOrOtherField
extends HTMLTextField
{
10 function __construct( $params ) {
11 parent
::__construct( $params );
13 if ( !in_array( 'other', $this->mOptions
, true ) ) {
15 isset( $params['other'] )
17 : wfMessage( 'htmlform-selectorother-other' )->text();
18 // Have 'other' always as first element
19 $this->mOptions
= array( $msg => 'other' ) +
$this->mOptions
;
24 function getInputHTML( $value ) {
27 if ( $value !== false ) {
28 $value = strval( $value );
29 $valInSelect = in_array(
30 $value, HTMLFormField
::flattenOptions( $this->getOptions() ), true
34 $selected = $valInSelect ?
$value : 'other';
36 $select = new XmlSelect( $this->mName
, $this->mID
, $selected );
37 $select->addOptions( $this->getOptions() );
39 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
41 $tbAttribs = array( 'id' => $this->mID
. '-other', 'size' => $this->getSize() );
43 if ( !empty( $this->mParams
['disabled'] ) ) {
44 $select->setAttribute( 'disabled', 'disabled' );
45 $tbAttribs['disabled'] = 'disabled';
48 if ( isset( $this->mParams
['tabindex'] ) ) {
49 $select->setAttribute( 'tabindex', $this->mParams
['tabindex'] );
50 $tbAttribs['tabindex'] = $this->mParams
['tabindex'];
53 $select = $select->getHTML();
55 if ( isset( $this->mParams
['maxlength'] ) ) {
56 $tbAttribs['maxlength'] = $this->mParams
['maxlength'];
59 if ( $this->mClass
!== '' ) {
60 $tbAttribs['class'] = $this->mClass
;
63 $textbox = Html
::input( $this->mName
. '-other', $valInSelect ?
'' : $value, 'text', $tbAttribs );
65 return "$select<br />\n$textbox";
68 function getInputOOUI( $value ) {
73 * @param WebRequest $request
77 function loadDataFromRequest( $request ) {
78 if ( $request->getCheck( $this->mName
) ) {
79 $val = $request->getText( $this->mName
);
81 if ( $val === 'other' ) {
82 $val = $request->getText( $this->mName
. '-other' );
87 return $this->getDefault();