Skip to content

Commit

Permalink
Add custom widget to support multiple file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
vctrklndr committed Aug 21, 2024
1 parent e6c0a36 commit 93a5973
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions wagtailstreamforms/wagtailstreamforms_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from django.utils.translation import gettext_lazy as _
from wagtail import blocks

from django.forms.widgets import ClearableFileInput

from wagtailstreamforms.conf import get_setting
from wagtailstreamforms.fields import BaseField, register

Expand Down Expand Up @@ -212,7 +214,18 @@ def get_form_block(self):
)


class MultiFileInput(ClearableFileInput):
input_type = 'file'
template_name = 'django/forms/widgets/multifileinput.html'

def __init__(self, attrs=None, *args, **kwargs):
attrs = attrs or {}
attrs.update({'multiple': True})
super().__init__(attrs, *args, **kwargs)


class MultiFileField(BaseField):
widget = MultiFileInput()
field_class = forms.FileField
widget = forms.widgets.FileInput(attrs={"multiple": True})
icon = "doc-full-inverse"
Expand Down

0 comments on commit 93a5973

Please sign in to comment.