1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Simplified SelectFilter2 with Element.closest().

https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
This commit is contained in:
Jon Dufresne 2020-03-14 13:45:18 -07:00 committed by Carlton Gibson
parent 99cefea360
commit 9cf4e40b84

View File

@ -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');