Skip to content

Commit

Permalink
Show link/identifier errors at the related fields
Browse files Browse the repository at this point in the history
We now display the link/identifier exists (or blank) errors at the
field group they apply to. Previously we only displayed these errors at
the main error summary at the top of the page.

Also moves the 'How users apply' section to the bottom of page which
makes the grouping more obvious.
  • Loading branch information
1pretz1 committed Jun 27, 2023
1 parent 202afe4 commit fb3de84
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
42 changes: 24 additions & 18 deletions app/views/metadata_fields/_licences.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,6 @@
%>
<% end %>
<div class="additional-field-context-section">
<h2>How users apply</h2>

<p>Enter either the website where users can apply for the licence, or the licence identifier.</p>
</div>

<%= render layout: "shared/form_group", locals: { f: f, field: :licence_transaction_will_continue_on, label: "Name of website where users apply" } do %>
<%= f.text_field :licence_transaction_will_continue_on, class: 'form-control' %>
<% end %>
<%= render layout: "shared/form_group", locals: { f: f, field: :licence_transaction_continuation_link, label: "Link to where users apply" } do %>
<%= f.text_field :licence_transaction_continuation_link, class: 'form-control' %>
<% end %>
<%= render layout: "shared/form_group", locals: { f: f, field: :licence_transaction_licence_identifier, label: "Licence identifier" } do %>
<%= f.text_field :licence_transaction_licence_identifier, class: 'form-control' %>
<% end %>
<%= render "shared/form_group", f: f, field: :primary_publishing_organisation, label: "Publishing organisation" do %>
<%= f.select :primary_publishing_organisation,
organisations_options,
Expand All @@ -72,3 +54,27 @@
}
%>
<% end %>

<div class="additional-field-context-section">
<h2>How users apply</h2>

<% if field_has_errors(@document, :base) %>
<div class="elements-error">
<p class="elements-error-message"><%= t("activemodel.errors.models.licence_transaction.attributes.base.link_and_identifier_exists") %></p>
</div>
<% else %>
<p>Enter either the website where users can apply for the licence, or the licence identifier.</p>
<% end %>
</div>

<%= render layout: "shared/form_group", locals: { f: f, field: :licence_transaction_will_continue_on, label: "Name of website where users apply" } do %>
<%= f.text_field :licence_transaction_will_continue_on, class: 'form-control' %>
<% end %>
<%= render layout: "shared/form_group", locals: { f: f, field: :licence_transaction_continuation_link, label: "Link to where users apply" } do %>
<%= f.text_field :licence_transaction_continuation_link, class: 'form-control' %>
<% end %>
<%= render layout: "shared/form_group", locals: { f: f, field: :licence_transaction_licence_identifier, label: "Licence identifier" } do %>
<%= f.text_field :licence_transaction_licence_identifier, class: 'form-control' %>
<% end %>
3 changes: 3 additions & 0 deletions spec/features/creating_a_licence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
expect(page).to have_content(attributes[:summary][:blank])
expect(page).to have_content(attributes[:body][:blank])
expect(page).to have_content(attributes[:licence_transaction_industry][:blank])
within(".additional-field-context-section p.elements-error-message") do
attributes[:base][:link_and_identifier_exists]
end
end

scenario "saving a new licence with valid data" do
Expand Down

0 comments on commit fb3de84

Please sign in to comment.