From 3461c59cfe25dc2cb98e417166f0dfe86a623e86 Mon Sep 17 00:00:00 2001 From: Mira Weller Date: Mon, 25 Nov 2024 16:08:20 +0100 Subject: [PATCH] Move countries-with-vat-id logic to addressform.js --- .../static/pretixbase/js/addressform.js | 19 +++++++++++++++++++ src/pretix/static/pretixcontrol/js/ui/main.js | 18 ------------------ src/pretix/static/pretixpresale/js/ui/main.js | 18 ------------------ 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/src/pretix/static/pretixbase/js/addressform.js b/src/pretix/static/pretixbase/js/addressform.js index 2e6ea0fde..89e999178 100644 --- a/src/pretix/static/pretixbase/js/addressform.js +++ b/src/pretix/static/pretixbase/js/addressform.js @@ -43,4 +43,23 @@ $(function () { } dependency.on("change", update); }); + + $("input[name$=vat_id][data-countries-with-vat-id]").each(function () { + var dependent = $(this), + dependency_country = $(this).closest(".panel-body, form").find('select[name$=country]'), + dependency_id_is_business_1 = $(this).closest(".panel-body, form").find('input[id$=id_is_business_1]'), + update = function (ev) { + if (dependency_id_is_business_1.length && !dependency_id_is_business_1.prop("checked")) { + dependent.closest(".form-group").hide(); + } else if (dependent.attr('data-countries-with-vat-id').split(',').includes(dependency_country.val())) { + dependent.closest(".form-group").show(); + } else { + dependent.closest(".form-group").hide(); + } + }; + update(); + dependency_country.on("change", update); + dependency_id_is_business_1.on("change", update); + }); + }); diff --git a/src/pretix/static/pretixcontrol/js/ui/main.js b/src/pretix/static/pretixcontrol/js/ui/main.js index 118c89fb0..86a515171 100644 --- a/src/pretix/static/pretixcontrol/js/ui/main.js +++ b/src/pretix/static/pretixcontrol/js/ui/main.js @@ -434,24 +434,6 @@ var form_handlers = function (el) { dependency.closest('.form-group').find('input[name=' + dependency.attr("name") + ']').on("dp.change", update); }); - $("input[name$=vat_id][data-countries-with-vat-id]").each(function () { - var dependent = $(this), - dependency_country = $(this).closest(".panel-body, form").find('select[name$=country]'), - dependency_id_is_business_1 = $(this).closest(".panel-body, form").find('input[id$=id_is_business_1]'), - update = function (ev) { - if (dependency_id_is_business_1.length && !dependency_id_is_business_1.prop("checked")) { - dependent.closest(".form-group").hide(); - } else if (dependent.attr('data-countries-with-vat-id').split(',').includes(dependency_country.val())) { - dependent.closest(".form-group").show(); - } else { - dependent.closest(".form-group").hide(); - } - }; - update(); - dependency_country.on("change", update); - dependency_id_is_business_1.on("change", update); - }); - el.find("div.scrolling-choice:not(.no-search)").each(function () { if ($(this).find("input[type=text]").length > 0) { return; diff --git a/src/pretix/static/pretixpresale/js/ui/main.js b/src/pretix/static/pretixpresale/js/ui/main.js index bf9bbe33e..68d68cdea 100644 --- a/src/pretix/static/pretixpresale/js/ui/main.js +++ b/src/pretix/static/pretixpresale/js/ui/main.js @@ -517,24 +517,6 @@ $(function () { dependency.closest('.form-group, form').find('input[name=' + dependency.attr("name") + ']').on("dp.change", update); }); - $("input[name$=vat_id][data-countries-with-vat-id]").each(function () { - var dependent = $(this), - dependency_country = $(this).closest(".panel-body, form").find('select[name$=country]'), - dependency_id_is_business_1 = $(this).closest(".panel-body, form").find('input[id$=id_is_business_1]'), - update = function (ev) { - if (dependency_id_is_business_1.length && !dependency_id_is_business_1.prop("checked")) { - dependent.closest(".form-group").hide(); - } else if (dependent.attr('data-countries-with-vat-id').split(',').includes(dependency_country.val())) { - dependent.closest(".form-group").show(); - } else { - dependent.closest(".form-group").hide(); - } - }; - update(); - dependency_country.on("change", update); - dependency_id_is_business_1.on("change", update); - }); - form_handlers($("body")); var local_tz = moment.tz.guess()