1
0
mirror of https://github.com/django/django.git synced 2025-06-05 03:29:12 +00:00

Updated formset remove event listener- creates some sort of error but causes filter to reset

This commit is contained in:
DhanyaShah 2024-12-06 19:11:49 -05:00
parent 62e557d25a
commit f2c1baec44

View File

@ -326,12 +326,14 @@ Requires core.js and SelectBox.js.
}); });
document.addEventListener('formset:removed', function(e) { document.addEventListener('formset:removed', function(e) {
const inlineElement = e.target; // The removed inline element. const inlineElement = e.target;
const field_id = inlineElement.querySelector('select.filtered')?.id; const field = inlineElement.querySelector('select.filtered');
if (field_id) { if (field) {
// Remove any references or event listeners related to the field_id. const field_id = field.id.replace('_from', ''); // Remove '_from' suffix if present
const fromBox = document.getElementById(field_id + '_from'); const fromBox = document.getElementById(field_id + '_from');
const toBox = document.getElementById(field_id + '_to'); const toBox = document.getElementById(field_id + '_to');
// Remove elements if present
if (fromBox) fromBox.remove(); if (fromBox) fromBox.remove();
if (toBox) toBox.remove(); if (toBox) toBox.remove();
console.log(`Cleaned up SelectFilter for field_id: ${field_id}`); console.log(`Cleaned up SelectFilter for field_id: ${field_id}`);