Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2016-04-05 04:25:38 +0300
committerRobert Speicher <rspeicher@gmail.com>2016-04-05 04:37:07 +0300
commit7a2370f74060b2f065e3602700fe1b33fda4685c (patch)
tree0c23a588515e857598d5e389cd55aa816d3cfe35 /app/helpers/form_helper.rb
parent2ed6cd9e469ffcdb60f21d1738de1eff8c258432 (diff)
Standardize the way we check for and display form errors
- Some views had a "Close" button. We've removed this, because we don't want users accidentally hiding the validation errors and not knowing what needs to be fixed. - Some views used `li`, some used `p`, some used `span`. We've standardized on `li`. - Some views only showed the first error. We've standardized on showing all of them. - Some views added an `#error_explanation` div, which we've made standard.
Diffstat (limited to 'app/helpers/form_helper.rb')
-rw-r--r--app/helpers/form_helper.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/helpers/form_helper.rb b/app/helpers/form_helper.rb
new file mode 100644
index 00000000000..6a43be2cf3e
--- /dev/null
+++ b/app/helpers/form_helper.rb
@@ -0,0 +1,18 @@
+module FormHelper
+ def form_errors(model)
+ return unless model.errors.any?
+
+ pluralized = 'error'.pluralize(model.errors.count)
+ headline = "The form contains the following #{pluralized}:"
+
+ content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do
+ content_tag(:h4, headline) <<
+ content_tag(:ul) do
+ model.errors.full_messages.
+ map { |msg| content_tag(:li, msg) }.
+ join.
+ html_safe
+ end
+ end
+ end
+end