From c5dcd6b66451bde8e3bc245d9d1252661f0fcdd4 Mon Sep 17 00:00:00 2001 From: Julien Cougnaud Date: Fri, 17 Nov 2023 13:39:33 +0100 Subject: [PATCH] WIP --- contrib/forms/__init__.py | 10 ++++++++++ static/admission/admission.css | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/contrib/forms/__init__.py b/contrib/forms/__init__.py index 33162b6f..98b622e0 100644 --- a/contrib/forms/__init__.py +++ b/contrib/forms/__init__.py @@ -236,11 +236,21 @@ class Media: ) +class AdmissionFileBoundField(forms.BoundField): + @property + def bound_css_class(self): + if self.value() in self.field.empty_values: + return 'empty-file-upload' + + class AdmissionFileUploadField(FileUploadField): def __init__(self, **kwargs): kwargs.setdefault('mimetypes', DEFAULT_MIME_TYPES) super().__init__(**kwargs) + def get_bound_field(self, form, field_name): + return AdmissionFileBoundField(form=form, field=self, name=field_name) + def get_example_text(example: str): return _("e.g.: %(example)s") % {'example': example} diff --git a/static/admission/admission.css b/static/admission/admission.css index bd3dc5e1..e15afe71 100644 --- a/static/admission/admission.css +++ b/static/admission/admission.css @@ -393,4 +393,8 @@ body, html { .mt-1 { margin-top: 1em; -} \ No newline at end of file +} + +.required_field.empty-file-upload label, .required_field .empty-file-upload:first-child label { + color: #a94442; +}