Skip to content

Commit

Permalink
refactor and DRY up the multiple form error methods into #form_errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
alishaevn committed Jun 7, 2023
1 parent 72a92dd commit 74bd469
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 132 deletions.
104 changes: 2 additions & 102 deletions app/helpers/hyrax/work_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,109 +99,9 @@ def form_file_set_select_for(parent:)
end

##
# This helper retrieves errors based on form type.
#
# @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
# @return [String] specific error message
def in_works_ids_errors_for(form:)
case form
when Hyrax::ChangeSet
form.errors[:in_works_ids]
else
form.model.errors[:in_works_ids]
end
end

##
# This helper retrieves errors based on form type.
#
# @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
# @return [String] specific error message
def ordered_member_ids_errors_for(form:)
case form
when Hyrax::ChangeSet
form.errors[:ordered_member_ids]
else
form.model.errors[:ordered_member_ids]
end
end

##
# This helper retrieves errors based on form type.
#
# @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
# @return [String] specific error message
def visibility_errors_for(form:)
case form
when Hyrax::ChangeSet
form.errors[:visibility]
else
form.model.errors[:visibility]
end
end

##
# This helper retrieves errors based on form type.
#
# @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
# @return [String] specific error message
def embargo_release_date_errors_for(form:)
case form
when Hyrax::ChangeSet
form.errors[:embargo_release_date]
else
form.model.errors[:embargo_release_date]
end
end

##
# This helper retrieves errors based on form type.
#
# @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
# @return [String] specific error message
def visibility_after_embargo_errors_for(form:)
case form
when Hyrax::ChangeSet
form.errors[:visibility_after_embargo]
else
form.model.errors[:visibility_after_embargo]
end
end

##
# This helper retrieves errors based on form type.
#
# @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
# @return [String] specific error message
def lease_expiration_date_errors_for(form:)
case form
when Hyrax::ChangeSet
form.errors[:lease_expiration_date_errors]
else
form.model.errors[:lease_expiration_date_errors]
end
end

##
# This helper retrieves errors based on form type.
#
# @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
# @return [String] specific error message
def visibility_after_lease_errors_for(form:)
case form
when Hyrax::ChangeSet
form.errors[:visibility_after_lease]
else
form.model.errors[:visibility_after_lease]
end
end

##
# This helper retrieves errors based on form type.
#
# @param form [Hyrax::Forms::WorkForm] or Hyrax::ChangeSet
# @param form [WorkForm]
# @return [String] specific error message(s)
def full_collections_errors(form:)
def form_errors(form:)
error_messages = []
form.errors.messages.each_value { |v| error_messages << v.first }
error_messages.join('; ')
Expand Down
5 changes: 1 addition & 4 deletions app/views/_flash_msg.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
<div class="alert alert-danger alert-dismissable" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<%= @form.errors.full_messages_for(:base).send(SimpleForm.error_method) %>
<%= render 'form_in_works_error', f: @form %>
<%= render 'form_ordered_members_error', f: @form %>
<%= render 'form_collections_error', f: @form %>
<%= render 'form_visibility_error', f: @form %>
<%= form_errors(form: @form) %>
</div>
<% end %>
1 change: 0 additions & 1 deletion app/views/hyrax/base/_form_collections_error.html.erb

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/hyrax/base/_form_in_works_error.html.erb

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/hyrax/base/_form_ordered_members_error.html.erb

This file was deleted.

19 changes: 0 additions & 19 deletions app/views/hyrax/base/_form_visibility_error.html.erb

This file was deleted.

0 comments on commit 74bd469

Please sign in to comment.