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; +}