From eab1efd5f496e3b57fff88ba6329f5eb4689a935 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 14 Sep 2026 09:35:32 +0200 Subject: [PATCH] Phone number input: Fix workaround for prefixes shared between countries (fixes #6544) (#6545) * Phone number input: Fix workaround for prefixes shared between countries (fixes #6544) * Update src/pretix/base/forms/questions.py Co-authored-by: pajowu --------- Co-authored-by: pajowu --- src/pretix/base/forms/questions.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/pretix/base/forms/questions.py b/src/pretix/base/forms/questions.py index 21ea5824a4..bf5c758f88 100644 --- a/src/pretix/base/forms/questions.py +++ b/src/pretix/base/forms/questions.py @@ -350,16 +350,22 @@ class WrappedPhonePrefixSelect(Select): return super().render(name, value or self.initial, *args, **kwargs) def get_context(self, name, value, attrs): - if value and self.choices[1][0] != value: - matching_choices = len([1 for p, c in self.choices if p == value]) + # self.choices is lazy evaluated, needs to be realized to be modifiable + choices = list(self.choices) + if value and choices[1][0] != value: + matching_choices = len([1 for p, c in choices if p == value]) if matching_choices > 1: # Some countries share a phone prefix, for example +1 is used all over the Americas. # This causes a UX problem: If the default value or the existing data is +12125552368, # the widget will just show the first without an explicit country. - self.choices.insert(1, (value, value)) + self.choices = [ + choices[0], + (value, value), + *choices[1:], + ] context = super().get_context(name, value, attrs) return context