From c762b6899bbf64ecf7cb56ffdeab504a59e45ea4 Mon Sep 17 00:00:00 2001 From: Florian Date: Wed, 4 Nov 2015 19:38:01 +0100 Subject: [PATCH] HTMLForm: Do not render hidden elements as elements 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 | 4 ++++ includes/htmlform/HTMLForm.php | 19 +++++++++++-------- includes/htmlform/HTMLFormField.php | 9 +++++++++ includes/htmlform/HTMLHiddenField.php | 4 ++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/includes/htmlform/HTMLApiField.php b/includes/htmlform/HTMLApiField.php index f988e6224e..24a253eddd 100644 --- a/includes/htmlform/HTMLApiField.php +++ b/includes/htmlform/HTMLApiField.php @@ -16,4 +16,8 @@ class HTMLApiField extends HTMLFormField { public function getInputHTML( $value ) { return ''; } + + public function hasVisibleOutput() { + return false; + } } diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index e51620f208..94aae3c4b5 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -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 != ' ' && $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 != ' ' && $labelValue !== '' ) { + $hasLabel = true; + } - if ( get_class( $value ) !== 'HTMLHiddenField' && - get_class( $value ) !== 'HTMLApiField' - ) { $hasUserVisibleFields = true; } } elseif ( is_array( $value ) ) { diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php index 2e3fdb0ccf..28bfb66319 100644 --- a/includes/htmlform/HTMLFormField.php +++ b/includes/htmlform/HTMLFormField.php @@ -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 diff --git a/includes/htmlform/HTMLHiddenField.php b/includes/htmlform/HTMLHiddenField.php index e4695f7c51..00f734329b 100644 --- a/includes/htmlform/HTMLHiddenField.php +++ b/includes/htmlform/HTMLHiddenField.php @@ -59,4 +59,8 @@ class HTMLHiddenField extends HTMLFormField { public function canDisplayErrors() { return false; } + + public function hasVisibleOutput() { + return false; + } } -- 2.20.1