1
0
Fork 0
forked from OpenNeo/impress

Add errors helper to support form builder

It still has no good CSS to it, but that's okay, this is just to DRY it
up.
This commit is contained in:
Emi Matchu 2024-11-30 11:46:19 -08:00
parent 2d3d4051fe
commit 252f4f1df1
4 changed files with 18 additions and 18 deletions

View file

@ -3,6 +3,21 @@ module SupportFormHelper
attr_reader :template attr_reader :template
delegate :concat, :content_tag, :image_tag, to: :template, private: true delegate :concat, :content_tag, :image_tag, to: :template, private: true
def errors
return nil if object.errors.empty?
error_list = content_tag(:ul) do
object.errors.each do |error|
concat content_tag(:li, error.full_message)
end
end
content_tag(:p) do
concat "Could not save:"
concat error_list
end
end
def fields(&block) def fields(&block)
content_tag(:ul, class: "fields", &block) content_tag(:ul, class: "fields", &block)
end end

View file

@ -14,12 +14,7 @@
= image_tag @alt_style.preview_image_url, class: "alt-style-preview" = image_tag @alt_style.preview_image_url, class: "alt-style-preview"
= support_form_with model: @alt_style, class: "support-form" do |f| = support_form_with model: @alt_style, class: "support-form" do |f|
- if @alt_style.errors.any? = f.errors
%p
Could not save:
%ul.errors
- @alt_style.errors.each do |error|
%li= error.full_message
= f.fields do = f.fields do
= f.field do = f.field do

View file

@ -9,12 +9,7 @@
it will probably be reverted automatically when someone models it. it will probably be reverted automatically when someone models it.
= support_form_with model: @item, class: "support-form" do |f| = support_form_with model: @item, class: "support-form" do |f|
- if @item.errors.any? = f.errors
%p
Could not save:
%ul.errors
- @item.errors.each do |error|
%li= error.full_message
= f.fields do = f.fields do
= f.field do = f.field do

View file

@ -18,12 +18,7 @@
= outfit_viewer pet_state: @pet_state = outfit_viewer pet_state: @pet_state
= support_form_with model: [@pet_type, @pet_state] do |f| = support_form_with model: [@pet_type, @pet_state] do |f|
- if @pet_state.errors.any? = f.errors
%p
Could not save:
%ul.errors
- @pet_state.errors.each do |error|
%li= error.full_message
= f.fields do = f.fields do
= f.radio_grid_fieldset "Pose" do = f.radio_grid_fieldset "Pose" do