diff options
| author | Joseph Kocherhans <joseph@jkocherhans.com> | 2009-03-30 19:36:19 +0000 |
|---|---|---|
| committer | Joseph Kocherhans <joseph@jkocherhans.com> | 2009-03-30 19:36:19 +0000 |
| commit | 08056572e89a9ac1c958ef7d47efe576c76116da (patch) | |
| tree | 3e0b47592e03b2021be53be30fabf50212f81cda /tests/regressiontests/forms/formsets.py | |
| parent | 78cbc3acfa6d8ccbb8414ac04e477922822c8e50 (diff) | |
Fixed #9587. Formset.is_valid() now returns True if an invalid form is marked for deletion. Thanks for the test and intial patch, kratorius.
Note that this leaves the form and formset errors alone. Those forms still have errors, it's just that it doesn't matter that they're invalid in the context of the formset and deletion.
Also fixed #9665 while I was in there. Thanks, mark_hildreth.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10206 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/forms/formsets.py')
| -rw-r--r-- | tests/regressiontests/forms/formsets.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/regressiontests/forms/formsets.py b/tests/regressiontests/forms/formsets.py index 4fd0c17032..c3c89d078d 100644 --- a/tests/regressiontests/forms/formsets.py +++ b/tests/regressiontests/forms/formsets.py @@ -241,7 +241,7 @@ data. # FormSets with deletion ###################################################### -We can easily add deletion ability to a FormSet with an agrument to +We can easily add deletion ability to a FormSet with an argument to formset_factory. This will add a boolean field to each form instance. When that boolean field is True, the form will be in formset.deleted_forms @@ -286,6 +286,34 @@ True >>> [form.cleaned_data for form in formset.deleted_forms] [{'votes': 900, 'DELETE': True, 'choice': u'Fergie'}] +If we fill a form with something and then we check the can_delete checkbox for +that form, that form's errors should not make the entire formset invalid since +it's going to be deleted. + +>>> class CheckForm(Form): +... field = IntegerField(min_value=100) + +>>> data = { +... 'check-TOTAL_FORMS': '3', # the number of forms rendered +... 'check-INITIAL_FORMS': '2', # the number of forms with initial data +... 'check-0-field': '200', +... 'check-0-DELETE': '', +... 'check-1-field': '50', +... 'check-1-DELETE': 'on', +... 'check-2-field': '', +... 'check-2-DELETE': '', +... } +>>> CheckFormSet = formset_factory(CheckForm, can_delete=True) +>>> formset = CheckFormSet(data, prefix='check') +>>> formset.is_valid() +True + +If we remove the deletion flag now we will have our validation back. + +>>> data['check-1-DELETE'] = '' +>>> formset = CheckFormSet(data, prefix='check') +>>> formset.is_valid() +False # FormSets with ordering ###################################################### |
