#8171: Invalid formset when form is missing from POST data
-------------------------------------------------------+--------------------
          Reporter:  James Chua <[EMAIL PROTECTED]>  |         Owner:  brosner 
            Status:  new                               |     Milestone:  1.0    
 
         Component:  Forms                             |       Version:  SVN    
 
        Resolution:                                    |      Keywords:  
formsets
             Stage:  Accepted                          |     Has_patch:  0      
 
        Needs_docs:  0                                 |   Needs_tests:  0      
 
Needs_better_patch:  0                                 |  
-------------------------------------------------------+--------------------
Comment (by brosner):

 Ok, I have looked a bit more deeply into this problem. The test case
 provided above is slightly misleading. The data provided is invalid data
 and the reporter is expecting this to fail. When in reality that isn't a
 good test case. Here is an improved case clearly showing the problem:

 {{{
 # Handle when forms are missing in the POST data
 ##############################
 # See http://code.djangoproject.com/ticket/8171
 ###############################

 >>> ChoiceFormSet = formset_factory(Choice)

 >>> data = {
 ...     'choices-TOTAL_FORMS': '3', # the number of forms rendered
 ...     'choices-INITIAL_FORMS': '0', # the number of forms with initial
 data
 ...     'choices-0-choice': 'Calexico',
 ...     'choices-0-votes': '100',
 ...     # choices-1, choices-2, choices-3 are missing. Possibly due to
 some
 ...     # Javascript add/delete of the elements.
 ...     'choices-4-choice': 'The Decemberists',
 ...     'choices-4-votes': '200',
 ...     'choices-5-choice': '',
 ...     'choices-5-votes': '',
 ... }

 >>> formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
 >>> formset.is_valid()
 True
 >>> [form.cleaned_data for form in formset.forms]
 [{'votes': 100, 'choice': u'Calexico'}, {'votes': 200, 'choice': 'The
 Decemberists'}, {}]
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8171#comment:4>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to