Skip to content

Conversation

jnovinger
Copy link
Member

Fixes: #20551

The slug generation logic in reslug.ts looks for form fields using hard-coded ID selectors like #id_slug and #id_name. In quick-add modals, Django applies a quickadd prefix to form fields (introduced in #20542), resulting in IDs like #id_quickadd-slug and #id_quickadd-name. The logic couldn't find these prefixed fields, so automatic slug generation failed silently in quick-add modals.

This fix updates the field selectors to try both unprefixed and prefixed patterns using the nullish coalescing operator (??). The logic checks for the standard field ID first and falls back to the quickadd-prefixed ID if the standard one isn't found.

Manually tested automatic slug generation in both direct add forms and quick-add modals. Both the blur event (tab out of name field) and the explicit slug button click work correctly.

The slug generation logic in `reslug.ts` looks for form fields using hard-coded ID selectors like `#id_slug` and `#id_name`. In quick-add modals, Django applies a `quickadd` prefix to form fields (introduced in #20542), resulting in IDs like `#id_quickadd-slug` and `#id_quickadd-name`. The logic couldn't find these prefixed fields, so automatic slug generation failed silently in quick-add modals. This fix updates the field selectors to try both unprefixed and prefixed patterns using the nullish coalescing operator (`??`), checking for the standard field ID first and falling back to the quickadd-prefixed ID if the standard one isn't found.
@jnovinger jnovinger requested review from a team and jeremystretch and removed request for a team October 19, 2025 22:37
The slug generation logic required updates to support form prefixes like `quickadd`. Python-side changes
ensure `SlugField.get_bound_field()` updates the `slug-source` attribute to include the form prefix when
present, so JavaScript receives the correct prefixed field ID. `SlugWidget.__init__()` now adds a
`slug-field` class to enable selector-based field discovery. On the frontend, `reslug.ts` now uses class
selectors (`button.reslug` and `input.slug-field`) instead of ID-based lookups, eliminating the need for
fallback logic. The template was updated to use `class="reslug"` instead of `id="reslug"` on the button to
avoid ID duplication issues.
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.

Automatic slug generation doesn't work in quick-add modals

2 participants