Skip to content

Commit

Permalink
fix submission save/update error state
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jul 28, 2023
1 parent 5ddbca0 commit ce249cd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
16 changes: 15 additions & 1 deletion app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def create
@errors = ["Please enter a contact"]
end

render "new"
reset_agent_attributes
render 'new', status: 422
else
redirect_to "/ontologies/success/#{@ontology.acronym}"
end
Expand Down Expand Up @@ -84,4 +85,17 @@ def update

end

private

def reset_agent_attributes
helpers.agent_attributes.each do |attr|
current_val = @submission.send(attr)
new_values = Array(current_val).map { |x| LinkedData::Client::Models::Agent.find(x) }

new_values = new_values.first unless current_val.is_a?(Array)

@submission.send("#{attr}=", new_values)
end
end

end
15 changes: 0 additions & 15 deletions app/views/submissions/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@
frame.src = "?properties=" + selectedProperties + "&required=" + required.checked + "&show_sections=true"
}

- unless @errors.nil?
%div.form-group.row
%div.col-sm-8.offset-sm-2.enable-lists{style: "color:red;"}
%strong Errors On Form
%ul
- for error in @errors
- if error.is_a? Array
%ul
- error[1].each do |key, message|
%li
= message
- else
%li
= error

%div#editMetadataDiv
%div{:style => "width: 50%;margin: 3em auto;"}
%p{:style => "text-align: center;"}
Expand Down
12 changes: 12 additions & 0 deletions app/views/submissions/_form_content.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
= render TurboFrameComponent.new(id:id) do
- unless @errors.nil?
%div
%div.enable-lists{style: "color:red;"}
%strong Errors On Form
%ul
- Array(@errors).each do |error|
- error = error[:error] if error.is_a?(Hash) && error[:error]
- error.each do |key, value|
%li
- value = value.values if value.is_a?(Hash)
#{key}: #{Array(value).join(', ')}

= hidden_field object_name, :ontology, value: acronym
= hidden_field object_name, :id, value: submissionId
%div#general-card.mt-4
Expand Down

0 comments on commit ce249cd

Please sign in to comment.