Skip to content

Commit

Permalink
Migrate promotional feature links to new add-another
Browse files Browse the repository at this point in the history
Call the new publishing components add another template for promotional feature links
  • Loading branch information
dnkrj committed Nov 22, 2024
1 parent 19e7785 commit 884068c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
39 changes: 10 additions & 29 deletions app/views/admin/promotional_feature_items/_form_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,14 @@
legend_text: "Feature item links",
heading_size: "l",
} do %>
<div data-module="AddAnother" data-add-text="Add link" class="govuk-!-margin-bottom-4">
<%= form.fields_for :links do |link_form| %>
<div class="js-duplicate-fields-set">
<div class="govuk-!-margin-bottom-6">
<%= render "govuk_publishing_components/components/input", {
label: {
text: "URL",
},
name: "#{name}[[links_attributes][#{link_form.index}][url]",
id: "#{id}_links_attributes_#{link_form.index}_url",
value: link_form.object.url,
heading_size: "m",
error_items: errors_for(link_form.object.errors, :url),
} %>
<%= render "govuk_publishing_components/components/input", {
label: {
text: "Text",
},
name: "#{name}[[links_attributes][#{link_form.index}][text]",
id: "#{id}_links_attributes_#{link_form.index}_text",
value: link_form.object.text,
heading_size: "m",
error_items: errors_for(link_form.object.errors, :text),
} %>
</div>
</div>
<% end %>
</div>
<%= render "govuk_publishing_components/components/add_another", {
add_button_text: "Add link",
items: form.object.links.each_with_index.map do |link, index|
{
fields: render(partial: "link_fields", locals: { form:, link:, index:, name:, id: }),
destroy_checkbox: render("govuk_publishing_components/components/checkboxes", { name: "#{name}[links_attributes][#{index}][_destroy]", items: [{label: "Delete", value: "1" }]})
}
end,
empty: render(partial: "link_fields", locals: { form:, link: PromotionalFeatureLink.new, index: form.object.links.length, name:, id: }),
} %>
<% end %>
23 changes: 23 additions & 0 deletions app/views/admin/promotional_feature_items/_link_fields.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<%= form.fields_for :links, link do |link_form| %>
<%= render "govuk_publishing_components/components/input", {
label: {
text: "URL",
},
name: "#{name}[links_attributes][#{index}][url]",
id: "#{id}_links_attributes_#{index}_url",
value: link_form.object.url,
heading_size: "m",
error_items: errors_for(link_form.object.errors, :url),
} %>
<%= render "govuk_publishing_components/components/input", {
label: {
text: "Text",
},
name: "#{name}[links_attributes][#{index}][text]",
id: "#{id}_links_attributes_#{index}_text",
value: link_form.object.text,
heading_size: "m",
error_items: errors_for(link_form.object.errors, :text),
} %>
<% end %>

0 comments on commit 884068c

Please sign in to comment.