From 4152ee4e50b412cc0057958e0efdf4c440bd6e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=A4fer?= Date: Tue, 15 Oct 2019 11:40:28 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20#1408=20--=20Don't=20mark=20upload=20ques?= =?UTF-8?q?tion=20fields=20as=20required=20if=E2=80=A6=20(#1443)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pretix/base/forms/widgets.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pretix/base/forms/widgets.py b/src/pretix/base/forms/widgets.py index 6adb50e252..442ee53553 100644 --- a/src/pretix/base/forms/widgets.py +++ b/src/pretix/base/forms/widgets.py @@ -46,6 +46,14 @@ class TimePickerWidget(forms.TimeInput): class UploadedFileWidget(forms.ClearableFileInput): def __init__(self, *args, **kwargs): + # Browsers can't recognize that the server already has a file uploaded + # Don't mark this input as being required if we already have an answer + # (this needs to be done via the attrs, otherwise we wouldn't get the "required" star on the field label) + attrs = kwargs.get('attrs', {}) + if kwargs.get('required') and kwargs.get('initial'): + attrs.update({'required': None}) + kwargs.update({'attrs': attrs}) + self.position = kwargs.pop('position') self.event = kwargs.pop('event') self.answer = kwargs.pop('answer')