summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorDevin Cox <dcox@surefyre.co>2024-07-24 09:43:39 -0700
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-07-25 08:52:24 +0200
commitcd0479ff764272add5e0aba2afcf5649a241ca00 (patch)
treebb43bd1db5346a2dd15f1b9ffb3d4b75efcc0d72 /django
parentf359990e4909db8722820849d61a6f5724338723 (diff)
Fixed #35331 -- Updated dropdown lists with entries added via the '+' sign from M2M field.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
index bc3accea37..74d17bfc3e 100644
--- a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
+++ b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
@@ -87,7 +87,7 @@
}
}
- function updateRelatedSelectsOptions(currentSelect, win, objId, newRepr, newId) {
+ function updateRelatedSelectsOptions(currentSelect, win, objId, newRepr, newId, skipIds = []) {
// After create/edit a model from the options next to the current
// select (+ or :pencil:) update ForeignKey PK of the rest of selects
// in the page.
@@ -100,7 +100,7 @@
const selectsRelated = document.querySelectorAll(`[data-model-ref="${modelName}"] [data-context="available-source"]`);
selectsRelated.forEach(function(select) {
- if (currentSelect === select) {
+ if (currentSelect === select || skipIds && skipIds.includes(select.id)) {
return;
}
@@ -109,6 +109,11 @@
if (!option) {
option = new Option(newRepr, newId);
select.options.add(option);
+ // Update SelectBox cache for related fields.
+ if (window.SelectBox !== undefined && !SelectBox.cache[currentSelect.id]) {
+ SelectBox.add_to_cache(select.id, option);
+ SelectBox.redisplay(select.id);
+ }
return;
}
@@ -136,9 +141,14 @@
$(elem).trigger('change');
} else {
const toId = name + "_to";
+ const toElem = document.getElementById(toId);
const o = new Option(newRepr, newId);
SelectBox.add_to_cache(toId, o);
SelectBox.redisplay(toId);
+ if (toElem && toElem.nodeName.toUpperCase() === 'SELECT') {
+ const skipIds = [name + "_from"];
+ updateRelatedSelectsOptions(toElem, win, null, newRepr, newId, skipIds);
+ }
}
const index = relatedWindows.indexOf(win);
if (index > -1) {