Skip to content

Conversation

jnovinger
Copy link
Member

Fixes: #20542

Commit d222466 added form prefix support to the GET handler to fix Markdown preview functionality in quick add modals. The form prefix allows Django to properly namespace field names and IDs when rendering forms within the quick add modal context.

However, the corresponding change was not made to the POST handler. This created a mismatch where form fields were rendered with the quickadd- prefix during GET requests, but the POST handler instantiated forms without the prefix. When users submitted quick add forms, Django looked for unprefixed field names like address and status in the POST data, but the actual submitted data used prefixed names like quickadd-address and quickadd-status. This caused validation to fail immediately with "This field is required" errors for all required fields, making every quick add form unusable.

The fix adds the same prefix detection logic to the POST handler that was added to the GET handler, checking for the _quickadd parameter in the query string and applying the quickadd prefix when present. This ensures consistent form field naming between rendering and validation.

A regression test has been added to MACAddressTestCase to verify that MAC addresses can be successfully created via the quick add modal, preventing this issue from recurring. This test should be promoted to a template test whenever it becomes possible to determine if a model should support quick-add functionality.

Commit d222466 added form prefix support to the `GET` handler to fix
Markdown preview functionality in quick add modals. The form prefix
allows Django to properly namespace field names and IDs when rendering
forms within the quick add modal context.

However, the corresponding change was not made to the `POST` handler. This
created a mismatch where form fields were rendered with the `quickadd-`
prefix during `GET` requests, but the `POST` handler instantiated forms
without the prefix. When users submitted quick add forms, Django looked
for unprefixed field names like `address` and `status` in the `POST` data,
but the actual submitted data used prefixed names like `quickadd-address`
and `quickadd-status`. This caused validation to fail immediately with
"This field is required" errors for all required fields, making every
quick add form unusable.

The fix adds the same prefix detection logic to the `POST` handler that was
added to the `GET` handler, checking for the `_quickadd` parameter in the
query string and applying the `quickadd` prefix when present. This ensures
consistent form field naming between rendering and validation.

A regression test has been added to `MACAddressTestCase` to verify that MAC
addresses can be successfully created via the quick add modal, preventing
this issue from recurring. This test should be promoted to a template
test whenever it becomes possible to determine if a model should support
quick-add functionality.
@jnovinger jnovinger requested a review from arthanson October 9, 2025 21:16
@arthanson arthanson merged commit f052361 into main Oct 9, 2025
10 checks passed
@jnovinger jnovinger deleted the 20542-quick-add-forms-broken branch October 9, 2025 21:45
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.

Can't create new MAC address in the new form

2 participants