3 namespace MediaWiki\Widget
;
5 use OOUI\DropdownInputWidget
;
6 use OOUI\TextInputWidget
;
9 * Select and input widget.
11 * @copyright 2011-2017 MediaWiki Widgets Team and others; see AUTHORS.txt
14 class SelectWithInputWidget
extends \OOUI\Widget
{
17 /** @var TextInputWidget */
19 /** @var DropdownInputWidget */
20 protected $dropdowninput;
23 * A version of the SelectWithInputWidget, with `or` set to true.
25 * @param array $config Configuration options
26 * - array $config['textinput'] Configuration for the TextInputWidget
27 * - array $config['dropdowninput'] Configuration for the DropdownInputWidget
28 * - bool $config['or'] Configuration for whether the widget is dropdown AND input
29 * or dropdown OR input
30 * - bool $config['required'] Configuration for whether the widget is a required input.
32 public function __construct( array $config = [] ) {
33 // Configuration initialization
34 $config = array_merge(
37 'dropdowninput' => [],
44 if ( isset( $config['disabled'] ) && $config['disabled'] ) {
45 $config['textinput']['disabled'] = true;
46 $config['dropdowninput']['disabled'] = true;
49 $config['textinput']['required'] = $config['or'] ?
false : $config['required'];
50 $config['dropdowninput']['required'] = $config['required'];
52 parent
::__construct( $config );
55 $this->config
= $config;
56 $this->textinput
= new TextInputWidget( $config['textinput'] );
57 $this->dropdowninput
= new DropdownInputWidget( $config['dropdowninput'] );
61 ->addClasses( [ 'mw-widget-selectWithInputWidget' ] )
62 ->appendContent( $this->dropdowninput
, $this->textinput
);
65 protected function getJavaScriptClassName() {
66 return 'mw.widgets.SelectWithInputWidget';
69 public function getConfig( &$config ) {
70 $config['textinput'] = $this->config
['textinput'];
71 $config['dropdowninput'] = $this->config
['dropdowninput'];
72 $config['dropdowninput']['dropdown']['$overlay'] = true;
73 $config['or'] = $this->config
['or'];
74 $config['required'] = $this->config
['required'];
75 return parent
::getConfig( $config );