Skip to content

Commit

Permalink
Merge pull request #313 from ontoportal-lirmm/fix/nested-from-compone…
Browse files Browse the repository at this point in the history
…nt-empty-state

Fix: Nested form component empty state
  • Loading branch information
syphax-bouazzouni authored Jul 28, 2023
2 parents dfe08dc + e41cdca commit 041e43f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 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
18 changes: 9 additions & 9 deletions app/views/submissions/_form_content.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,16 @@
= text_area c.name, c.method_name, rows: 5, value: @submission.description, required: true, class: "form-control"

-# Home page
= attribute_text_field_container('homepage') do |c|
- c.help do
Enter a URL for the main page of your ontology.
= form_group_attribute('homepage') do
Enter a URL for the main page of your ontology.

-# Documentation page
= attribute_text_field_container('documentation') do |c|
- c.help do
Enter a URL for a page that provides ontology documentation.
= form_group_attribute('documentation') do
Enter a URL for a page that provides ontology documentation.

-# Publications page
= attribute_text_field_container('publication') do |c|
- c.help do
Enter a URL for a page that lists publications about your ontology.
= form_group_attribute('publication') do
Enter a URL for a page that lists publications about your ontology.

-# Used ontology engineering tool
= form_group_attribute("usedOntologyEngineeringTool")
Expand Down Expand Up @@ -105,6 +102,9 @@
= 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][#{@submission.contact.size}][email]"
= hidden_field_tag object_name+"[contact][#{@submission.contact.size}][name]"
- @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 041e43f

Please sign in to comment.