From eaa1a67d763291bd56fac3ccf92b66bf49c293c9 Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Wed, 16 Dec 2020 10:13:49 +0000 Subject: [PATCH] Add allowed_file_extensions arg to file_upload Safari has a bug where it stops input[type=file] elements working if they don't specify the types of file to accept (via the `accept` attribute). It seems to just effect certain versions of Mojave but completely blocks this action so worth fixing. This adds a 'allowed_file_extensions' keyword argument to the file_upload component to let you specify a value to be passed to `accept`. This was spotted on x-gov Slack: https://ukgovernmentdigital.slack.com/archives/C06GCJW7R/p1607952390112800 ...and StackOverflow: https://stackoverflow.com/q/64843459/679924 --- app/templates/components/file-upload.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/templates/components/file-upload.html b/app/templates/components/file-upload.html index 1908f1e48..4db7d00cc 100644 --- a/app/templates/components/file-upload.html +++ b/app/templates/components/file-upload.html @@ -2,6 +2,7 @@ {% macro file_upload( field, + allowed_file_extensions, action=None, button_text="Choose file", alternate_link=None, @@ -25,7 +26,8 @@ {% endif %} {{ field(**{ - 'class': 'file-upload-field' + 'class': 'file-upload-field', + 'accept': allowed_file_extensions }) }}