From 6a7bc64e112c82904973a37e9082876ff20ce01a Mon Sep 17 00:00:00 2001 From: Richard Schreiber Date: Wed, 19 Feb 2025 15:39:06 +0100 Subject: [PATCH] Fix selector for copying order/invoice answers to first ticket --- src/pretix/static/pretixpresale/js/ui/main.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pretix/static/pretixpresale/js/ui/main.js b/src/pretix/static/pretixpresale/js/ui/main.js index 34b84b807c..1d21d9f0b6 100644 --- a/src/pretix/static/pretixpresale/js/ui/main.js +++ b/src/pretix/static/pretixpresale/js/ui/main.js @@ -386,22 +386,29 @@ $(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); + + // 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); } 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); 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); } }); }