Ticket #5174: formsets-is_valid-5897.diff

File formsets-is_valid-5897.diff, 1.4 KB (added by Simon Litchfield <simon@…>, 17 years ago)

Fixes unbound formsets is_valid() to behave like standard forms - NOTE this patch also includes a patch from ticket 5173

  • django/newforms/formsets.py

     
    6161                    kwargs['files'] = self.files
    6262                add_form = FormClass(**kwargs)
    6363                self.add_fields(add_form, i)
     64                # HACK: Form is empty, lets re-create without data so it doesn't trip validation
     65                if self.data and add_form.is_empty():
     66                    del(kwargs['data'])
     67                    add_form = FormClass(**kwargs)
     68                    self.add_fields(add_form, i)
    6469                add_forms.append(add_form)
    6570            self._add_forms = add_forms
    6671        return self._add_forms
     
    6974    def _get_change_forms(self):
    7075        """Return a list of all the change forms in this ``FormSet``."""
    7176        FormClass = self.form_class
    72         if not hasattr(self, '_add_forms'):
     77        if not hasattr(self, '_change_forms'):
    7378            change_forms = []
    7479            for i in range(0, self.change_form_count):
    7580                kwargs = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i)}
     
    151156        return '%s-%s' % (self.prefix, index)
    152157
    153158    def is_valid(self):
     159        if not self.is_bound:
     160            return False
    154161        self.full_clean()
    155162        return self._is_valid
    156163
Back to Top