un1t / django-file-resubmit

It remembers selected files in form on validation errors.
76 stars 39 forks source link

Fix: attrs should be passed to __init__() of ResubmitBaseWidget's super class #24

Closed codeout closed 6 years ago

codeout commented 6 years ago

Hi un1t, thanks for your great library.

I'd like to specify attrs in ResubmitFileWidget just like FileInput(attrs={'accept': 'image/*'}).

ImageField(widget=ResubmitFileWidget(attrs={'accept': 'image/*'}))

This PR allows us to reflect the given argument.

Note: Inheritance hierarchy

  1. django.forms.Input
  2. -> django.forms.FileInput
  3. -> django.forms.ClearableFileInput
  4. -> ResubmitBaseWidget
# https://github.com/django/django/blob/master/django/forms/widgets.py

class Input(Widget):
    def __init__(self, attrs=None):
        if attrs is not None:
            attrs = attrs.copy()
            self.input_type = attrs.pop('type', self.input_type)
        super().__init__(attrs)
maddencs commented 6 years ago

:+1: