Two components share a name
The error
The error page has this title:
Components Share a Name
The sentence under the title names the route and the shared name:
Two or more components on the page returned from `index` use the same
name (`answer`). Drafter uses each component's name to match its value to
a parameter of the next route function, so every component needs its own
name.
The technical message below it lists the components that use the name:
payload.verification_failed: Payload verification failed for the page 'index':
The page returned from index has multiple components with the same name:
'answer' is used by: TextBox, SelectBox
Each component must have a unique name, because the name is how values
are matched to route parameters. Rename the duplicates.
What it means
Two or more inputs on one page use the same name. Names are how
submitted values are matched to route parameters. If two components
shared one name, one value would silently overwrite the other, so
Drafter stops the page instead of guessing which one you meant.
Where to look
Start with the route named in the message. Search its content list for the quoted name; the message lists which component types are using it.
Check
- A copy-paste mistake: a line containing
TextBox("answer")was duplicated, and the copy was never renamed. - Two questions, one name: two genuinely different inputs
(
TextBox("answer")andSelectBox("answer", ...)) that each deserve their own parameter. - A checkbox group on purpose: several checkboxes meant to submit together should be RelatedCheckBox, which is designed to share one name (and delivers a list).
Fix
Rename so each input has its own name, with a matching parameter on the receiving route:
TextBox("guess"),
SelectBox("category", ["animals", "history"]),
Button("Submit", "save")
@route
def save(state: State, guess: str, category: str) -> Page:
...
Confirm
The page renders again, and submitting fills both parameters. An
assert_has(index(state), TextBox("guess")) keeps the rename from
quietly regressing.
Prevent
Name inputs after the specific question they ask (pet_name,
pet_age), not after generic slots (input1, answer). Specific
names rarely collide.
Understand
Forms and input explains the name-to-parameter contract that this uniqueness rule protects.