Skip to content

Commit ae943de

Browse files
geographybuffclaude
andcommitted
Render a blank Add Another Item row after a failed partner request
The Add Another Item template rendered _item_request with object: outside locals:. With render partial: ... locals: ..., object: isn't passed as a local, so defined?(object) in the partial was false and fields_for rendered every submitted row into the template. After a failed submit, "Add Another Item" then cloned a copy of the first submitted item. Passing object in locals makes the template hold one blank row again. Resolves #5611 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d6f8290 commit ae943de

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎app/views/partners/requests/new.html.erb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</table>
4949
<div>
5050
<%= add_element_button('Add Another Item', container_selector: '.fields') do %>
51-
<%= render partial: 'item_request', locals: { form: form, item_units: @item_units }, object: @partner_request.item_requests.build %>
51+
<%= render partial: 'item_request', locals: { form: form, item_units: @item_units, object: @partner_request.item_requests.build } %>
5252
<% end %>
5353
</div>
5454

‎spec/requests/partners/requests_spec.rb‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,16 @@
329329
expect(response).to be_unprocessable
330330
expect(response.body).to include("Please ensure a single unit is selected for each item")
331331
end
332+
333+
it "renders a single blank row in the Add Another Item template" do
334+
post partners_requests_path, params: request_attributes
335+
336+
template = Nokogiri::HTML(response.body).at_css('template[data-form-input-target="addTemplate"]')
337+
rows = template.css("tr")
338+
expect(rows.size).to eq(1)
339+
expect(rows.css("option[selected]")).to be_empty
340+
expect(rows.at_css('input[name$="[quantity]"]')["value"]).to be_blank
341+
end
332342
end
333343
end
334344

0 commit comments

Comments
 (0)