* @todo FIXME: If made 'required', only the text field should be compulsory.
*/
class HTMLSelectAndOtherField extends HTMLSelectField {
- function __construct( $params ) {
+ public function __construct( $params ) {
if ( array_key_exists( 'other', $params ) ) {
// Do nothing
} elseif ( array_key_exists( 'other-message', $params ) ) {
$this->mOptions = [ $params['other'] => 'other' ] + $this->mOptions;
}
$this->mFlatOptions = self::flattenOptions( $this->getOptions() );
-
}
- function getInputHTML( $value ) {
+ public function getInputHTML( $value ) {
$select = parent::getInputHTML( $value[1] );
$textAttribs = [
return "$select<br />\n$textbox";
}
- function getInputOOUI( $value ) {
- return false;
+ protected function getOOUIModules() {
+ return [ 'mediawiki.widgets.SelectWithInputWidget' ];
+ }
+
+ public function getInputOOUI( $value ) {
+ $this->mParent->getOutput()->addModuleStyles( 'mediawiki.widgets.SelectWithInputWidget.styles' );
+
+ # TextInput
+ $textAttribs = [
+ 'id' => $this->mID . '-other',
+ 'name' => $this->mName . '-other',
+ 'size' => $this->getSize(),
+ 'class' => [ 'mw-htmlform-select-and-other-field' ],
+ 'data-id-select' => $this->mID,
+ 'value' => $value[2],
+ ];
+
+ $allowedParams = [
+ 'required',
+ 'autofocus',
+ 'multiple',
+ 'disabled',
+ 'tabindex',
+ 'maxlength',
+ ];
+
+ $textAttribs += OOUI\Element::configFromHtmlAttributes(
+ $this->getAttributes( $allowedParams )
+ );
+
+ if ( $this->mClass !== '' ) {
+ $textAttribs['classes'] = [ $this->mClass ];
+ }
+
+ # DropdownInput
+ $dropdownInputAttribs = [
+ 'name' => $this->mName,
+ 'id' => $this->mID,
+ 'options' => $this->getOptionsOOUI(),
+ 'value' => $value[1],
+ ];
+
+ $allowedParams = [
+ 'tabindex',
+ 'disabled',
+ ];
+
+ $dropdownInputAttribs += OOUI\Element::configFromHtmlAttributes(
+ $this->getAttributes( $allowedParams )
+ );
+
+ if ( $this->mClass !== '' ) {
+ $dropdownInputAttribs['classes'] = [ $this->mClass ];
+ }
+
+ return $this->getInputWidget( [
+ 'textinput' => $textAttribs,
+ 'dropdowninput' => $dropdownInputAttribs,
+ 'or' => false,
+ ] );
+ }
+
+ public function getInputWidget( $params ) {
+ return new Mediawiki\Widget\SelectWithInputWidget( $params );
}
/**
*
* @return array("<overall message>","<select value>","<text field value>")
*/
- function loadDataFromRequest( $request ) {
+ public function loadDataFromRequest( $request ) {
if ( $request->getCheck( $this->mName ) ) {
$list = $request->getText( $this->mName );
$text = $request->getText( $this->mName . '-other' );
return [ $final, $list, $text ];
}
- function getSize() {
+ public function getSize() {
return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45;
}
- function validate( $value, $alldata ) {
+ public function validate( $value, $alldata ) {
# HTMLSelectField forces $value to be one of the options in the select
# field, which is not useful here. But we do want the validation further up
# the chain
&& $this->mParams['required'] !== false
&& $value[1] === ''
) {
- return $this->msg( 'htmlform-required' )->parse();
+ return $this->msg( 'htmlform-required' );
}
return true;