mirror of
https://github.com/pretix/pretix.git
synced 2026-04-30 00:22:40 +00:00
Fix addressform handling reloading address-info while XHR-request is still running (Z#23210723) (#5558)
* Fix handling answers with null-value * fix handling re-requesting the same url while XHR is still running
This commit is contained in:
committed by
GitHub
parent
d9572420eb
commit
0f25a1d6c8
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user