Skip to content

Resolves #5611: Render a blank Add Another Item row after a failed partner request - #5743

Open
geographybuff wants to merge 1 commit into
rubyforgood:mainfrom
geographybuff:5611-add-another-item-blank-row
Open

geographybuff wants to merge 1 commit into
rubyforgood:mainfrom
geographybuff:5611-add-another-item-blank-row

Conversation

@geographybuff

Copy link
Copy Markdown
Contributor

Resolves #5611

Description

After a partner request fails validation, "Add Another Item" adds a copy of the first submitted item instead of a blank row.

Cause: app/views/partners/requests/new.html.erb rendered the template row with render partial: 'item_request', locals: { ... }, object: .... With locals: given, Rails doesn't pass object: as a local named object, so defined?(object) in _item_request.html.erb was false. form.fields_for :item_requests, nil then rendered every item request on the form into the <template>: the submitted rows plus the blank one built for the template. The Stimulus controller clones the template's first row, which is the first submitted item.

On a fresh form there are no submitted rows yet, so the bug only shows after a failed submit, as the issue describes.

Fix: move object: into locals: (one line). The template now holds one blank row, as it does on a fresh form.

partners/individuals_requests/new.html.erb uses the short render 'path', form: ..., object: ... form, which passes object as a local, so it isn't affected.

@augustocbx mentioned a fix for this in June; no PR for it was opened, and the issue was auto-unassigned on 2026-08-04.

AI disclosure: prepared with Claude Code (Claude Opus 5.5). It found the cause, wrote the fix and the spec, and ran the specs below.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • New request spec in spec/requests/partners/requests_spec.rb, under "when there are mixed units / on the same item" (a submit that fails validation with two rows). It parses the addTemplate <template> and expects exactly one tr, no option[selected] and an empty quantity.
    • Without the fix it fails: expected: 1, got: 3.
    • With the fix, bundle exec rspec spec/requests/partners/requests_spec.rb runs 34 examples, 0 failures.
  • erb_lint on the view and rubocop on the spec report no offenses.
  • The full suite (bundle exec rake) and system specs were not run locally; CI will run them.

🤖 Generated with Claude Code

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 rubyforgood#5611

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@dorner dorner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passes tech review. Over to @janeewheatley @ruestitch for QA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Partner Request Add Another Item auto-populates with first item when returning from failed validation

2 participants