Ticket #10828: 10828.diff

File 10828.diff, 2.1 KB (added by Colin Copeland, 15 years ago)
  • django/forms/formsets.py

    diff -r d0dc9aaff6af django/forms/formsets.py
    a b  
    144144                # if this is an extra form and hasn't changed, don't consider it
    145145                if i >= self.initial_form_count() and not form.has_changed():
    146146                    continue
    147                 if form.cleaned_data[DELETION_FIELD_NAME]:
     147                field = form.fields[DELETION_FIELD_NAME]
     148                raw_value = form._raw_value(DELETION_FIELD_NAME)
     149                should_delete = field.clean(raw_value)
     150                if should_delete:
    148151                    self._deleted_form_indexes.append(i)
    149152        return [self.forms[i] for i in self._deleted_form_indexes]
    150153    deleted_forms = property(_get_deleted_forms)
     
    231234                raw_value = form._raw_value(DELETION_FIELD_NAME)
    232235                should_delete = field.clean(raw_value)
    233236                if should_delete:
     237                    if not form.is_valid():
     238                        form.cleaned_data = {}
    234239                    # This form is going to be deleted so any of its errors
    235240                    # should not cause the entire formset to be invalid.
    236241                    continue
  • tests/regressiontests/forms/formsets.py

    diff -r d0dc9aaff6af tests/regressiontests/forms/formsets.py
    a b  
    308308>>> formset.is_valid()
    309309True
    310310
     311The formset is valid (due to short circuiting forms marked for deletion), but
     312not all forms are valid:
     313
     314>>> [form.is_valid() for form in formset.forms]
     315[True, False, True]
     316
     317But we can still access the cleaned_data attribute for each form:
     318
     319>>> [form.cleaned_data for form in formset.forms]
     320[{'field': 200, 'DELETE': False}, {}, {}]
     321
     322And access the deleted form:
     323
     324>>> len(formset.deleted_forms)
     3251
     326>>> formset._deleted_form_indexes
     327[1]
     328
    311329If we remove the deletion flag now we will have our validation back.
    312330
    313331>>> data['check-1-DELETE'] = ''
Back to Top