This article will help a lot:
http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/

The simplest way is just to override __init__ method of your Form
class.
For example, you need to show to user additional fields, depending on
previous choices.

class MyFirstForm(forms.Form):
    choices = forms.ChoiceField({'foo': 'first choice', 'boo': 'second
choice'})

class MySecondForm(forms.Form)
    def __init__(self, choice, *args, **kwargs):
        super(MySecondForm, self).__init__(*args, **kwargs)
        if choice == 'second choice':
            self.fields['newfield'] = forms.CharField()

Then in the view you should instantiate your form in the next way:
......
if request.method == 'POST':
    form = MyFirstForm(request.POST)
    if form.is_valid():
        choice = form.cleaned_data['choices']
        form = MySecondForm(choice)
.....
I have not tested code above, but I effectively have implemented this
technique in my apllication.
Also I don't recommend you to use FormWizard, especially when dealing
with dynamic forms.

With regards,
Max.

On May 27, 10:32 pm, Jochem Berndsen <joc...@functor.nl> wrote:
> All,
>
> Is there an easy way to include "conditional fields" in forms within the
> Django framework. By "conditional fields", I mean fields that are shown
> or not shown depending on earlier choices the user made in the form.
> What would be the canonical way to implement this?
>
> Thanks for your consideration.
> Regards,
>
> --
> Jochem Berndsen | joc...@functor.nl
> GPG: 0xE6FABFAB
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to