HTMLMultiSelectField: Use CheckboxMultiselectInputWidget
authorBartosz Dziewoński <matma.rex@gmail.com>
Mon, 30 May 2016 11:16:51 +0000 (13:16 +0200)
committerJames D. Forrester <jforrester@wikimedia.org>
Tue, 31 May 2016 22:45:25 +0000 (15:45 -0700)
Depends on I6f9fad0a462b43ac45c117cd3a3e11c36781cf11 in OOjs UI.

Bug: T123935
Change-Id: I62322739b985cc2143b5094d23b3aa5dd1004c25

includes/htmlform/HTMLMultiSelectField.php
resources/src/mediawiki/mediawiki.htmlform.ooui.css

index 1aaa3e8..23125bd 100644 (file)
@@ -65,21 +65,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
 
        protected function getOneCheckbox( $checked, $attribs, $label ) {
                if ( $this->mParent instanceof OOUIHTMLForm ) {
-                       if ( $this->mOptionsLabelsNotFromMessage ) {
-                               $label = new OOUI\HtmlSnippet( $label );
-                       }
-                       return new OOUI\FieldLayout(
-                               new OOUI\CheckboxInputWidget( [
-                                       'name' => "{$this->mName}[]",
-                                       'selected' => $checked,
-                               ] + OOUI\Element::configFromHtmlAttributes(
-                                       $attribs
-                               ) ),
-                               [
-                                       'label' => $label,
-                                       'align' => 'inline',
-                               ]
-                       );
+                       throw new MWException( 'HTMLMultiSelectField#getOneCheckbox() is not supported' );
                } else {
                        $elementFunc = [ 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' ];
                        $checkbox =
@@ -99,6 +85,38 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
                }
        }
 
+       /**
+        * Get the OOUI version of this field.
+        *
+        * @since 1.28
+        * @param string[] $value
+        * @return OOUI\CheckboxMultiselectInputWidget
+        */
+       public function getInputOOUI( $value ) {
+               $attr = $this->getTooltipAndAccessKey();
+               $attr['id'] = $this->mID;
+               $attr['name'] = "{$this->mName}[]";
+
+               $attr['value'] = $value;
+               $attr['options'] = $this->getOptionsOOUI();
+
+               if ( $this->mOptionsLabelsNotFromMessage ) {
+                       foreach ( $attr['options'] as &$option ) {
+                               $option['label'] = new OOUI\HtmlSnippet( $option['label'] );
+                       }
+               }
+
+               $attr += OOUI\Element::configFromHtmlAttributes(
+                       $this->getAttributes( [ 'disabled', 'tabindex' ] )
+               );
+
+               if ( $this->mClass !== '' ) {
+                       $attr['classes'] = [ $this->mClass ];
+               }
+
+               return new OOUI\CheckboxMultiselectInputWidget( $attr );
+       }
+
        /**
         * @param WebRequest $request
         *
index 8f0ad6b..47a662f 100644 (file)
@@ -18,7 +18,3 @@
        margin-right: 5%;
        width: 39%;
 }
-
-.oo-ui-fieldLayout .oo-ui-fieldLayout.oo-ui-fieldLayout-align-inline {
-  margin-bottom: 0;
-}