HTMLForm: Do not render hidden elements as elements
authorFlorian <florian.schmidt.stargatewissen@gmail.com>
Wed, 4 Nov 2015 18:38:01 +0000 (19:38 +0100)
committerFlorianschmidtwelzow <florian.schmidt.stargatewissen@gmail.com>
Mon, 9 Nov 2015 16:16:40 +0000 (16:16 +0000)
Hidden elements doesn't need an extra element in the DOM, but OOUIHTMLForm
would render one, wrapped into a fieldLayout div.

Fix this by adding the possibility to bypass the output, and only construct
a HTMLFormField element and run the output method.

Bug: T117768
Change-Id: I8c9d2ff862f1b14d72a9bb9e1a51e8745af6d1f4

includes/htmlform/HTMLApiField.php
includes/htmlform/HTMLForm.php
includes/htmlform/HTMLFormField.php
includes/htmlform/HTMLHiddenField.php

index f988e62..24a253e 100644 (file)
@@ -16,4 +16,8 @@ class HTMLApiField extends HTMLFormField {
        public function getInputHTML( $value ) {
                return '';
        }
+
+       public function hasVisibleOutput() {
+               return false;
+       }
 }
index e51620f..94aae3c 100644 (file)
@@ -1390,16 +1390,19 @@ class HTMLForm extends ContextSource {
                                $v = empty( $value->mParams['nodata'] )
                                        ? $this->mFieldData[$key]
                                        : $value->getDefault();
-                               $html[] = $value->$getFieldHtmlMethod( $v );
 
-                               $labelValue = trim( $value->getLabel() );
-                               if ( $labelValue != '&#160;' && $labelValue !== '' ) {
-                                       $hasLabel = true;
-                               }
+                               $retval = $value->$getFieldHtmlMethod( $v );
+
+                               // check, if the form field should be added to
+                               // the output.
+                               if ( $value->hasVisibleOutput() ) {
+                                       $html[] = $retval;
+
+                                       $labelValue = trim( $value->getLabel() );
+                                       if ( $labelValue != '&#160;' && $labelValue !== '' ) {
+                                               $hasLabel = true;
+                                       }
 
-                               if ( get_class( $value ) !== 'HTMLHiddenField' &&
-                                       get_class( $value ) !== 'HTMLApiField'
-                               ) {
                                        $hasUserVisibleFields = true;
                                }
                        } elseif ( is_array( $value ) ) {
index 2e3fdb0..28bfb66 100644 (file)
@@ -86,6 +86,15 @@ abstract class HTMLFormField {
                return call_user_func_array( $callback, $args );
        }
 
+       /**
+        * If this field has a user-visible output or not. If not,
+        * it will not be rendered
+        *
+        * @return bool
+        */
+       public function hasVisibleOutput() {
+               return true;
+       }
 
        /**
         * Fetch a field value from $alldata for the closest field matching a given
index e4695f7..00f7343 100644 (file)
@@ -59,4 +59,8 @@ class HTMLHiddenField extends HTMLFormField {
        public function canDisplayErrors() {
                return false;
        }
+
+       public function hasVisibleOutput() {
+               return false;
+       }
 }