Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #35911 -- FilteredSelectMultiple Widget Not Functional in Inline Formset After Form Deletion #18903

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Alanna-Cao
Copy link

@Alanna-Cao Alanna-Cao commented Dec 9, 2024

Trac ticket number: 35911

ticket-35911

Branch description

This PR addressed the issue where the FilteredSelectMultiple widget became non-functional when inline formsets in Django admin were dynamically deleted. The widget's icons and dropdown filters failed to refresh correctly, and event handlers were not reinitialized, causing usability issues.

The implemented solution focused on improving the handling of icons and dropdown filters. The key changes included:

  • Updating SelectFilter2.js to handle icon refresh more robustly, skipping updates if necessary elements were missing.
  • Reinitializing the widget's functionality when formsets were dynamically added or removed.
  • Cleaning up any residual references during formset removal to ensure proper functionality.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello! Thank you for your contribution 💪

As it's your first contribution be sure to check out the patch review checklist.

If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!

If you have any design or process questions then you can ask in the Django forum.

Welcome aboard ⛵️!

@EngFarisAlsmawi
Copy link

There are a same issue already exists in select2 (autocomplete in inline formset)

Copy link
Contributor

@sarahboyce sarahboyce left a comment

Choose a reason for hiding this comment

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

Please can you resolve the test and linter failures before putting this back in the review queue ⭐

@@ -1,63 +1,17 @@
import globals from "globals";
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert these changes

Comment on lines +20 to +25
venv/
.venv/
env/
.env/
myproject/staticfiles
myproject/
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert these changes

Comment on lines +33 to +43

// document.addEventListener('formset:added', function(e) {
// const formId = e.target.id; // Get the form ID
// const newField = formId.querySelector('select.selectfilter');
// if (newField) {
// const fieldName = newField.dataset.fieldName;
// const isStacked = parseInt(newField.dataset.isStacked, 10);
// SelectFilter.init(newField.id, fieldName, isStacked);
// }
// });

Copy link
Contributor

Choose a reason for hiding this comment

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

We try not to comment out blocks of code. If this is not needed, it should be removed

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.

4 participants