From 4905b13f251e55e1fbd2cfa5bb42d9d5b5befd14 Mon Sep 17 00:00:00 2001 From: Alex Turchyn Date: Fri, 2 Jun 2023 01:23:56 +0300 Subject: [PATCH] update form error styles --- .../devise/shared/_error_messages.html.erb | 22 +++++++++++-------- app/views/shared/_field_error.html.erb | 4 ++++ .../storage_settings/_disk_form.html.erb | 3 +-- config/initializers/field_error_proc.rb | 6 ++++- 4 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 app/views/shared/_field_error.html.erb diff --git a/app/views/devise/shared/_error_messages.html.erb b/app/views/devise/shared/_error_messages.html.erb index 6b7735d6..52de543c 100644 --- a/app/views/devise/shared/_error_messages.html.erb +++ b/app/views/devise/shared/_error_messages.html.erb @@ -1,14 +1,18 @@ <% if resource.errors.any? %>
-

- <%= I18n.t('errors.messages.not_saved', +
+
+ +
+

+ <%= I18n.t('errors.messages.not_saved', count: resource.errors.count, - resource: resource.class.model_name.human.downcase) %> -

-
    - <% resource.errors.full_messages.each do |message| %> -
  • <%= message %>
  • - <% end %> -
+ resource: resource.class.model_name.human.downcase) %>

+ <% resource.errors.full_messages.each do |message| %> +

<%= message %>

+ <% end %> +
+ + <% end %> diff --git a/app/views/shared/_field_error.html.erb b/app/views/shared/_field_error.html.erb new file mode 100644 index 00000000..1305c8c6 --- /dev/null +++ b/app/views/shared/_field_error.html.erb @@ -0,0 +1,4 @@ +<% 'input-error' %> + + <%= message %> + diff --git a/app/views/storage_settings/_disk_form.html.erb b/app/views/storage_settings/_disk_form.html.erb index 2478a938..4e2560ca 100644 --- a/app/views/storage_settings/_disk_form.html.erb +++ b/app/views/storage_settings/_disk_form.html.erb @@ -5,13 +5,12 @@
-

Store all files on disk

+

Store all files on disk

No configs are needed but make sure your disk is persistent
(not suitable for Heroku and other PaaS)

-
diff --git a/config/initializers/field_error_proc.rb b/config/initializers/field_error_proc.rb index 50a59c4b..2393455d 100644 --- a/config/initializers/field_error_proc.rb +++ b/config/initializers/field_error_proc.rb @@ -8,8 +8,12 @@ ActionView::Base.field_error_proc = proc do |html_tag, instance| field_name = instance.object.class.human_attribute_name(instance.instance_variable_get(:@method_name).to_s) + parsed_html_tag = Nokogiri::HTML::DocumentFragment.parse(html_tag) + parsed_html_tag.children.add_class 'input-error' + html_tag = parsed_html_tag.to_s.html_safe + result = html_tag - result += ApplicationController.helpers.tag.div("#{field_name} #{errors}") if errors.present? + result += ApplicationController.helpers.tag.label(ApplicationController.render(partial: 'shared/field_error', locals: { message: "#{field_name} #{errors}" }), class: 'label') if errors.present? result end