diff -r d0dc9aaff6af django/forms/formsets.py
a
|
b
|
|
144 | 144 | # if this is an extra form and hasn't changed, don't consider it |
145 | 145 | if i >= self.initial_form_count() and not form.has_changed(): |
146 | 146 | 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: |
148 | 151 | self._deleted_form_indexes.append(i) |
149 | 152 | return [self.forms[i] for i in self._deleted_form_indexes] |
150 | 153 | deleted_forms = property(_get_deleted_forms) |
… |
… |
|
231 | 234 | raw_value = form._raw_value(DELETION_FIELD_NAME) |
232 | 235 | should_delete = field.clean(raw_value) |
233 | 236 | if should_delete: |
| 237 | if not form.is_valid(): |
| 238 | form.cleaned_data = {} |
234 | 239 | # This form is going to be deleted so any of its errors |
235 | 240 | # should not cause the entire formset to be invalid. |
236 | 241 | continue |
diff -r d0dc9aaff6af tests/regressiontests/forms/formsets.py
a
|
b
|
|
308 | 308 | >>> formset.is_valid() |
309 | 309 | True |
310 | 310 | |
| 311 | The formset is valid (due to short circuiting forms marked for deletion), but |
| 312 | not all forms are valid: |
| 313 | |
| 314 | >>> [form.is_valid() for form in formset.forms] |
| 315 | [True, False, True] |
| 316 | |
| 317 | But 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 | |
| 322 | And access the deleted form: |
| 323 | |
| 324 | >>> len(formset.deleted_forms) |
| 325 | 1 |
| 326 | >>> formset._deleted_form_indexes |
| 327 | [1] |
| 328 | |
311 | 329 | If we remove the deletion flag now we will have our validation back. |
312 | 330 | |
313 | 331 | >>> data['check-1-DELETE'] = '' |