Compare commits

...

2 Commits

Author SHA1 Message Date
Richard Schreiber
8a669ab231 add trigger change to fix e.g. country-state-refresh 2025-02-19 15:45:16 +01:00
Richard Schreiber
6a7bc64e11 Fix selector for copying order/invoice answers to first ticket 2025-02-19 15:39:06 +01:00

View File

@@ -385,23 +385,30 @@ $(function () {
" #id_city, #id_country, #id_state").change(function () {
if (copy_to_first_ticket) {
var $first_ticket_form = $(".questions-form").first().find("[data-addonidx=0]");
$first_ticket_form.find("[id$=" + this.id.substring(3) + "]").val(this.value);
$first_ticket_form.find("[id$=" + this.id.substring(3) + "]").val(this.value).trigger("change");
// when matching by placeholder or label, make sure to always match the tagName of the element
// filter any checkbox/radio inputs as copied input is either select or type=email|text, but could be
// matched when custom answer options have the same label, see https://github.com/pretix/pretix/issues/4860
var selectorPrefix = this.tagName + ":not([type='checkbox'], [type='radio'])";
if (this.placeholder) {
$first_ticket_form.find("[placeholder='" + CSS.escape(this.placeholder) + "']").val(this.value);
$first_ticket_form.find(
selectorPrefix + "[placeholder='" + CSS.escape(this.placeholder) + "']"
).val(this.value).trigger("change");
}
var label = $("label[for=" + this.id +"]").first().contents().filter(function () {
return this.nodeType != Node.ELEMENT_NODE || !this.classList.contains("sr-only");
}).text().trim();
if (label) {
// match to placeholder and label
$first_ticket_form.find("[placeholder='" + CSS.escape(label) + "']").val(this.value);
$first_ticket_form.find(selectorPrefix + "[placeholder='" + CSS.escape(label) + "']").val(this.value).trigger("change");
var v = this.value;
$first_ticket_form.find("label").each(function() {
var text = $(this).first().contents().filter(function () {
return this.nodeType != Node.ELEMENT_NODE || !this.classList.contains("sr-only");
}).text().trim();
if (text == label) {
$("#" + this.getAttribute("for")).val(v);
$(selectorPrefix + "#" + this.getAttribute("for")).val(v).trigger("change");
}
});
}