diff --git a/django/contrib/admin/static/admin/js/cancel.js b/django/contrib/admin/static/admin/js/cancel.js index 3f7dfb42a7..04ec812a4a 100644 --- a/django/contrib/admin/static/admin/js/cancel.js +++ b/django/contrib/admin/static/admin/js/cancel.js @@ -3,7 +3,11 @@ $(function() { $('.cancel-link').on('click', function(e) { e.preventDefault(); - window.history.back(); + if (window.location.search.indexOf('&_popup=1') === -1) { + window.history.back(); // Go back if not a popup. + } else { + window.close(); // Otherwise, close the popup. + } }); }); })(django.jQuery); diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 3985e16b47..1d49c789ec 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -4394,6 +4394,20 @@ class SeleniumTests(AdminSeleniumTestCase): self.assertEqual(select.first_selected_option.text, '---------') self.assertEqual(select.first_selected_option.get_attribute('value'), '') + def test_inline_with_popup_cancel_delete(self): + """Clicking ""No, take me back" on a delete popup closes the window.""" + parent = ParentWithUUIDPK.objects.create(title='test') + related_with_parent = RelatedWithUUIDPKModel.objects.create(parent=parent) + self.admin_login(username='super', password='secret', login_url=reverse('admin:index')) + change_url = reverse('admin:admin_views_relatedwithuuidpkmodel_change', args=(related_with_parent.id,)) + self.selenium.get(self.live_server_url + change_url) + self.selenium.find_element_by_id('delete_id_parent').click() + self.wait_for_popup() + self.selenium.switch_to.window(self.selenium.window_handles[-1]) + self.selenium.find_element_by_xpath('//a[text()="No, take me back"]').click() + self.selenium.switch_to.window(self.selenium.window_handles[0]) + self.assertEqual(len(self.selenium.window_handles), 1) + def test_list_editable_raw_id_fields(self): parent = ParentWithUUIDPK.objects.create(title='test') parent2 = ParentWithUUIDPK.objects.create(title='test2')