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 29, 2024
1 parent 3fa0bf3 commit cdb1f08
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 33 deletions.
40 changes: 11 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,15 @@
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", {
fieldset_legend: "Link",
add_button_text: "Add link",
items: form.object.links.each_with_index.map do |link, index|
{
fields: render(partial: "admin/promotional_feature_items/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: "admin/promotional_feature_items/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: "s",
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: "s",
error_items: errors_for(link_form.object.errors, :text),
} %>
<% end %>
12 changes: 8 additions & 4 deletions features/step_definitions/promotional_features_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
fill_in "Item title url", with: "http://big-cheese.co"
attach_file :image, Rails.root.join("test/fixtures/big-cheese.960x640.jpg")
fill_in "Image description", with: "The Big Cheese"
fill_in "URL", with: "http://test.com"
fill_in "Text", with: "someText"
within ".js-add-another__fieldset", match: :first do
fill_in "URL", with: "http://test.com"
fill_in "Text", with: "someText"
end

click_button "Save"
end
Expand All @@ -47,8 +49,10 @@
fill_in "YouTube video URL (required)", with: "https://www.youtube.com/watch?v=fFmDQn9Lbl4"
fill_in "YouTube description (required)", with: "Description of video."
fill_in "Image description", with: "The Big Cheese"
fill_in "URL", with: "http://test.com"
fill_in "Text", with: "someText"
within ".js-add-another__fieldset", match: :first do
fill_in "URL", with: "http://test.com"
fill_in "Text", with: "someText"
end

click_button "Save"
end
Expand Down

0 comments on commit cdb1f08

Please sign in to comment.