Don't add label-elements for elements that doesn't have one
authorFlorian <florian.schmidt.stargatewissen@gmail.com>
Sun, 13 Mar 2016 23:11:42 +0000 (00:11 +0100)
committerFlorian <florian.schmidt.stargatewissen@gmail.com>
Sun, 13 Mar 2016 23:15:36 +0000 (00:15 +0100)
Fix the OOUI field element implementation to conditionally add
labels to the FieldLayout (only if the label isn't empty). Also
add setShowEmptyLabel( false ) to HTMLButtonField (labels usually
aren't set outside of the button, the button itself should have a label).

Bug: T129821
Change-Id: I0499bb82245273519e77c80e78bc431588875a85

includes/htmlform/HTMLButtonField.php
includes/htmlform/HTMLFormField.php

index 0b07765..16417fc 100644 (file)
@@ -56,6 +56,8 @@ class HTMLButtonField extends HTMLFormField {
                        $this->buttonLabel = $info['buttonlabel-raw'];
                }
 
+               $this->setShowEmptyLabel( false );
+
                parent::__construct( $info );
        }
 
index 6e5d656..a9c7632 100644 (file)
@@ -610,12 +610,17 @@ abstract class HTMLFormField {
                $config = [
                        'classes' => [ "mw-htmlform-field-$fieldType", $this->mClass ],
                        'align' => $this->getLabelAlignOOUI(),
-                       'label' => new OOUI\HtmlSnippet( $this->getLabel() ),
                        'help' => $helpText !== null ? new OOUI\HtmlSnippet( $helpText ) : null,
                        'errors' => $errors,
                        'infusable' => $infusable,
                ];
 
+               // the element could specify, that the label doesn't need to be added
+               $label = $this->getLabel();
+               if ( $label ) {
+                       $config['label'] = new OOUI\HtmlSnippet( $label );
+               }
+
                return $this->getFieldLayoutOOUI( $inputField, $config );
        }