diff --git a/src/pretix/base/forms/questions.py b/src/pretix/base/forms/questions.py index 42a22ee5b9..82a125631a 100644 --- a/src/pretix/base/forms/questions.py +++ b/src/pretix/base/forms/questions.py @@ -573,6 +573,7 @@ class BaseQuestionsForm(forms.Form): the attendee name for admission tickets, if the corresponding setting is enabled, as well as additional questions defined by the organizer. """ + address_validation = False def __init__(self, *args, **kwargs): """ @@ -920,8 +921,14 @@ class BaseQuestionsForm(forms.Form): v.widget.attrs['autocomplete'] = 'section-{} '.format(self.prefix) + v.widget.attrs.get('autocomplete', '') def clean(self): + from pretix.base.addressvalidation import \ + validate_address # local import to prevent impact on startup time + d = super().clean() + if self.address_validation: + self.cleaned_data = d = validate_address(d, True) + if d.get('city') and d.get('country') and str(d['country']) in COUNTRIES_WITH_STATE_IN_ADDRESS: if not d.get('state'): self.add_error('state', _('This field is required.')) diff --git a/src/pretix/presale/forms/checkout.py b/src/pretix/presale/forms/checkout.py index 99c60dc38d..ce6071bbdd 100644 --- a/src/pretix/presale/forms/checkout.py +++ b/src/pretix/presale/forms/checkout.py @@ -148,6 +148,7 @@ class QuestionsForm(BaseQuestionsForm): as well as additional questions defined by the organizer. """ required_css_class = 'required' + address_validation = True def __init__(self, *args, **kwargs): allow_save = kwargs.pop('allow_save', False)