I am trying to validate a formset that I have and am having problems with the forms within the set. If i call is_valid on a formset after a POST, it seems that the individual forms aren't validating within the set. For example, if the code below is executed, the resulting log looks like this: DEBUG 17:00:49,800 views.test:55 poll data: {'question': u'test'} DEBUG 17:00:49,801 views.test:58 formset data: {} DEBUG 17:00:49,801 views.test:60 form data: [{}]
I am not sure how those resulting forms are valid, the CharField is required? thanks, Matt here is the sample code: forms.py: from django import forms from django.forms.formsets import formset_factory class PollForm(forms.Form): question = forms.CharField(max_length=200) class ChoiceForm(forms.Form): choice = forms.CharField(max_length=200, required=True) ChoiceFormSet = formset_factory(ChoiceForm) views.py: from site.polls.forms import * def test(request): if request.POST: poll = PollForm(request.POST, prefix='poll') choice = ChoiceFormSet(request.POST) if poll.is_valid(): logging.debug("poll data: %s" %poll.cleaned_data) for form in choice.forms: if form.is_valid(): logging.debug("formset data %s" % form.cleaned_data) if choice.is_valid(): logging.debug("form data %s" + choice.cleaned_data) else: poll = PollForm( prefix='poll') choice = ChoiceFormSet() return render_to_response('polls/test.html', {'poll': poll, 'choices':choice}) test.html: <form action="/polls/test" method="post"> {{choices.management_form}} {{poll.as_p}} <fieldset> <legend>Choices</legend> <ul id="choices"> {% for form in choices.forms %} <li>{{form.as_p}}</li> {% endfor %} </ul> </fieldset> <input type="submit" value="Create" /> </form> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---