forked from CGM_Public/pretix_original
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) {
|
const update = function (ev) {
|
||||||
if (xhr) {
|
|
||||||
xhr.abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
dependents.state.prop("data-selected-value", dependents.state.val());
|
dependents.state.prop("data-selected-value", dependents.state.val());
|
||||||
if (dependents.transmission_type) {
|
if (dependents.transmission_type) {
|
||||||
dependents.transmission_type.prop("data-selected-value", dependents.transmission_type.val());
|
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);
|
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)) {
|
if (!(url in responseCache)) {
|
||||||
responseCache[url] = new Promise((resolve, reject) => {
|
responseCache[url] = xhr = $.ajax({
|
||||||
xhr = $.ajax({
|
dataType: "json",
|
||||||
dataType: "json",
|
url: url,
|
||||||
url: url,
|
timeout: 3000,
|
||||||
timeout: 3000,
|
});
|
||||||
success: resolve,
|
|
||||||
}).fail(function(){
|
|
||||||
reject();
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.resolve(responseCache[url]).then(function (data) {
|
Promise.resolve(responseCache[url]).then(function (data) {
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ function questions_init_profiles(el) {
|
|||||||
for (var p of profiles) {
|
for (var p of profiles) {
|
||||||
data = {};
|
data = {};
|
||||||
for (var key of Object.keys(p)) {
|
for (var key of Object.keys(p)) {
|
||||||
if (key.startsWith("_")) {
|
if (key.startsWith("_") || p[key] === null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
matched_field = getMatchingInput(key, p[key], scope);
|
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
|
// _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");
|
var $fields = $('[name$="' + key + '"], [name$="' + key + '_0"], [name$="' + key + '_1"]', scope).not(":disabled");
|
||||||
if ($fields.length) return $fields;
|
if ($fields.length) return $fields;
|
||||||
|
if (!answer) return null;
|
||||||
|
|
||||||
if (answer.identifier) {
|
if (answer.identifier) {
|
||||||
$label = $('[data-identifier="' + answer.identifier + '"]', scope);
|
$label = $('[data-identifier="' + answer.identifier + '"]', scope);
|
||||||
|
|||||||
Reference in New Issue
Block a user