Skip to content

Commit 7d25584

Browse files
committed
update for django 3.2.19 (MultipleFileField)
1 parent b32bf28 commit 7d25584

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

wagtailstreamforms/wagtailstreamforms_fields.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,27 @@ def get_form_block(self):
212212
)
213213

214214

215+
class MultipleFileInput(forms.ClearableFileInput):
216+
allow_multiple_selected = True
217+
218+
219+
class MultipleFileField(forms.FileField):
220+
def __init__(self, *args, **kwargs):
221+
kwargs.setdefault("widget", MultipleFileInput())
222+
super().__init__(*args, **kwargs)
223+
224+
def clean(self, data, initial=None):
225+
single_file_clean = super().clean
226+
if data and isinstance(data, (list, tuple)):
227+
result = [single_file_clean(d, initial) for d in data]
228+
else:
229+
result = single_file_clean(data, initial)
230+
return result
231+
232+
215233
class MultiFileField(BaseField):
216-
field_class = forms.FileField
217-
widget = forms.widgets.FileInput(attrs={"multiple": True})
234+
field_class = MultipleFileField
235+
widget = MultipleFileInput(attrs={"multiple": True})
218236
icon = "doc-full-inverse"
219237
label = _("Files field")
220238

0 commit comments

Comments
 (0)