diff --git a/src/pretix/static/pretixbase/js/addressform.js b/src/pretix/static/pretixbase/js/addressform.js index baedc8da7..b1aa04e76 100644 --- a/src/pretix/static/pretixbase/js/addressform.js +++ b/src/pretix/static/pretixbase/js/addressform.js @@ -95,10 +95,6 @@ $(function () { } const update = function (ev) { - if (xhr) { - xhr.abort(); - } - dependents.state.prop("data-selected-value", dependents.state.val()); if (dependents.transmission_type) { dependents.transmission_type.prop("data-selected-value", dependents.transmission_type.val()); @@ -119,17 +115,24 @@ $(function () { url.searchParams.append("transmission_type_required", !dependents.transmission_type.find("option[value='-']").length); } + if (xhr && url in responseCache) { + if (responseCache[url] == xhr) { + // already requested this, but XHR is still running and will resolve promise + // only re-resolve promise for JSON-data in responseCache[url] + return; + } else { + // abort current xhr as it is not the one we want + // aborting deletes responseCache[url] but async + xhr.abort(); + } + } + if (!(url in responseCache)) { - responseCache[url] = new Promise((resolve, reject) => { - xhr = $.ajax({ - dataType: "json", - url: url, - timeout: 3000, - success: resolve, - }).fail(function(){ - reject(); - }); - }) + responseCache[url] = xhr = $.ajax({ + dataType: "json", + url: url, + timeout: 3000, + }); } Promise.resolve(responseCache[url]).then(function (data) { diff --git a/src/pretix/static/pretixpresale/js/ui/questions.js b/src/pretix/static/pretixpresale/js/ui/questions.js index ce054945e..d2317b07a 100644 --- a/src/pretix/static/pretixpresale/js/ui/questions.js +++ b/src/pretix/static/pretixpresale/js/ui/questions.js @@ -168,7 +168,7 @@ function questions_init_profiles(el) { for (var p of profiles) { data = {}; for (var key of Object.keys(p)) { - if (key.startsWith("_")) { + if (key.startsWith("_") || p[key] === null) { continue; } matched_field = getMatchingInput(key, p[key], scope); @@ -230,6 +230,7 @@ function questions_init_profiles(el) { // _0 and _1 are e.g. for phone-fields. name-fields have their parts/keys already split var $fields = $('[name$="' + key + '"], [name$="' + key + '_0"], [name$="' + key + '_1"]', scope).not(":disabled"); if ($fields.length) return $fields; + if (!answer) return null; if (answer.identifier) { $label = $('[data-identifier="' + answer.identifier + '"]', scope);