From 9cf4e40b846d5ad5cc0aaba98454cf1f0d0fac9e Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 14 Mar 2020 13:45:18 -0700 Subject: [PATCH] Simplified SelectFilter2 with Element.closest(). https://developer.mozilla.org/en-US/docs/Web/API/Element/closest --- django/contrib/admin/static/admin/js/SelectFilter2.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/django/contrib/admin/static/admin/js/SelectFilter2.js b/django/contrib/admin/static/admin/js/SelectFilter2.js index aa49254257..e522091429 100644 --- a/django/contrib/admin/static/admin/js/SelectFilter2.js +++ b/django/contrib/admin/static/admin/js/SelectFilter2.js @@ -6,14 +6,6 @@ Requires jQuery, core.js, and SelectBox.js. */ (function($) { 'use strict'; - function findForm(node) { - // returns the node of the form containing the given node - if (node.tagName.toLowerCase() !== 'form') { - return findForm(node.parentNode); - } - return node; - } - window.SelectFilter = { init: function(field_id, field_name, is_stacked) { if (field_id.match(/__prefix__/)) { @@ -154,7 +146,7 @@ Requires jQuery, core.js, and SelectBox.js. SelectFilter.refresh_icons(field_id); } }); - findForm(from_box).addEventListener('submit', function() { + from_box.closest('form').addEventListener('submit', function() { SelectBox.select_all(field_id + '_to'); }); SelectBox.init(field_id + '_from');