Skip to content

Commit

Permalink
update nested form component to have an empty state to send to the back
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jul 28, 2023
1 parent 7f0702f commit 9ce277c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/components/nested_form_inputs_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class NestedFormInputsComponent < ViewComponent::Base
renders_one :template
renders_one :header
renders_many :rows
renders_one :empty_state

def initialize(object_name: '')
super
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
= inline_svg 'icons/delete.svg'
%div.titles
= header
%div.d-none
= empty_state
- rows.each_with_index do |row , index|
%div.d-flex.align-items-center.nested-form-wrapper.my-1{'data-new-record': 'true'}
%div{style: 'width: 90%'}
Expand Down
11 changes: 8 additions & 3 deletions app/helpers/submissions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def metadata_section(id, label, collapsed: true, parent_id: nil, &block)

def attribute_container(attr, required: false, &block)
if show_attribute?(attr, required)
content_tag(:div) do
capture(&block)
end
content_tag(:div) do
capture(&block)
end
end
end

def inline_save?
!@inline_save.nil? && @inline_save
Expand Down Expand Up @@ -355,6 +355,11 @@ def generate_list_field_input(attr, name, values, field_func)
c.template do
method(field_func).call("#{name}[NEW_RECORD]", '', :id => attr["attribute"].to_s + "_" + @ontology.acronym, class: "metadataInput form-control my-1")
end

c.empty_state do
hidden_field_tag "#{name}[#{values.size}]"
end

values.each_with_index do |metadata_val, i|
c.row do
method(field_func).call("#{name}[#{i}]", metadata_val, :id => "submission_#{attr["attribute"].to_s}" + "_" + @ontology.acronym, class: "metadataInput my-1 form-control")
Expand Down
2 changes: 2 additions & 0 deletions app/views/submissions/_form_content.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
= render NestedFormInputsComponent.new do |c|
- c.template do
= render partial: "submissions/submission_contact_form", locals: {contact: nil, index: 'NEW_RECORD'}
- c.empty_state do
= hidden_field_tag object_name+"[contact][#{index.to_s.upcase}][email]"
- @submission.contact.each_with_index do |contact, i|
- c.row do
= render partial: "submissions/submission_contact_form", locals: {contact: contact, index: i}
Expand Down

0 comments on commit 9ce277c

Please sign in to comment.