From 70cddaae3210ff4ad170b18015719164f08032c4 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Tue, 3 Feb 2015 07:08:59 -0800 Subject: [PATCH] Add smarter UI for form errors Summary: Just makes the UI cleaner on full width or dialog forms (and mobile) Test Plan: run into a bunch of errors, test mobile breakpoints. {F281585} Reviewers: btrahan, epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D11638 --- resources/celerity/map.php | 6 +-- src/view/form/control/AphrontFormControl.php | 39 ++++++++++---------- webroot/rsrc/css/phui/phui-form-view.css | 15 +++++++- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 2949e1ebf2..3a79325338 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -7,7 +7,7 @@ */ return array( 'names' => array( - 'core.pkg.css' => 'fabafbdb', + 'core.pkg.css' => '8be366b7', 'core.pkg.js' => '65e04767', 'darkconsole.pkg.js' => '8ab24e01', 'differential.pkg.css' => '8af45893', @@ -129,7 +129,7 @@ return array( 'rsrc/css/phui/phui-error-view.css' => 'ad042fdd', 'rsrc/css/phui/phui-feed-story.css' => 'c9f3a0b5', 'rsrc/css/phui/phui-fontkit.css' => '9ae12677', - 'rsrc/css/phui/phui-form-view.css' => 'aad06f2a', + 'rsrc/css/phui/phui-form-view.css' => '8b78a986', 'rsrc/css/phui/phui-form.css' => '9aecbda1', 'rsrc/css/phui/phui-header-view.css' => '083669db', 'rsrc/css/phui/phui-icon.css' => 'd35aa857', @@ -778,7 +778,7 @@ return array( 'phui-font-icon-base-css' => '3dad2ae3', 'phui-fontkit-css' => '9ae12677', 'phui-form-css' => '9aecbda1', - 'phui-form-view-css' => 'aad06f2a', + 'phui-form-view-css' => '8b78a986', 'phui-header-view-css' => '083669db', 'phui-icon-view-css' => 'd35aa857', 'phui-image-mask-css' => '5a8b09c8', diff --git a/src/view/form/control/AphrontFormControl.php b/src/view/form/control/AphrontFormControl.php index 1fca2ba457..3c63d527d4 100644 --- a/src/view/form/control/AphrontFormControl.php +++ b/src/view/form/control/AphrontFormControl.php @@ -181,6 +181,22 @@ abstract class AphrontFormControl extends AphrontView { array('class' => 'aphront-form-input'), $this->renderInput()); + $error = null; + if (strlen($this->getError())) { + $error = $this->getError(); + if ($error === true) { + $error = phutil_tag( + 'span', + array('class' => 'aphront-form-error aphront-form-required'), + pht('Required')); + } else { + $error = phutil_tag( + 'span', + array('class' => 'aphront-form-error'), + $error); + } + } + if (strlen($this->getLabel())) { $label = phutil_tag( 'label', @@ -188,29 +204,14 @@ abstract class AphrontFormControl extends AphrontView { 'class' => 'aphront-form-label', 'for' => $this->getID(), ), - $this->getLabel()); + array( + $this->getLabel(), + $error,)); } else { $label = null; $custom_class .= ' aphront-form-control-nolabel'; } - if (strlen($this->getError())) { - $error = $this->getError(); - if ($error === true) { - $error = phutil_tag( - 'div', - array('class' => 'aphront-form-error aphront-form-required'), - pht('Required')); - } else { - $error = phutil_tag( - 'div', - array('class' => 'aphront-form-error'), - $error); - } - } else { - $error = null; - } - if (strlen($this->getCaption())) { $caption = phutil_tag( 'div', @@ -222,6 +223,7 @@ abstract class AphrontFormControl extends AphrontView { $classes = array(); $classes[] = 'aphront-form-control'; + $classes[] = 'grouped'; $classes[] = $custom_class; $style = $this->controlStyle; @@ -241,7 +243,6 @@ abstract class AphrontFormControl extends AphrontView { $error, $input, $caption, - phutil_tag('div', array('style' => 'clear: both;'), ''), )); } } diff --git a/webroot/rsrc/css/phui/phui-form-view.css b/webroot/rsrc/css/phui/phui-form-view.css index c315dd7ced..28f4883cc6 100644 --- a/webroot/rsrc/css/phui/phui-form-view.css +++ b/webroot/rsrc/css/phui/phui-form-view.css @@ -71,6 +71,10 @@ padding-top: 5px; } +.aphront-form-label .aphront-form-error { + display: none; +} + .aphront-dialog-body .phui-form-full-width { margin-top: -10px; } @@ -81,8 +85,15 @@ .device-phone .aphront-form-error, .phui-form-full-width .aphront-form-error { - float: none; - width: 100%; + display: none; +} + +.device-phone .aphront-form-label .aphront-form-error, +.phui-form-full-width .aphront-form-label .aphront-form-error { + display: block; + float: right; + padding: 0; + width: auto; } .device-phone .aphront-form-drag-and-drop-upload {