You can add and modify fields on a form in the form's __init__
function.

class MyForm(forms.Form):
    country = forms.ChoiceField()
    def __init__(self, *args, **kwargs):
         super(MyForm, self).__init__(*args, **kwargs)
        self.fields['country'].choices = \
          [(c.iso_code, c.name) for c in get_all_choices()]

Perhaps you'll need to do it in the view.
You can create the form instance both before you bind it with
something like request.POST or if you do it later.
E.g.
def my_view(request):
    form = MyForm()
    form.fields['country'].choices = get_my_country_choices
(request.user)
    if request.method == "POST":
        # bind the form
        form.is_bound = True
        form.data = request.POST
        if form.is_valid():
    return render(request, 'my_template.html', locals())

            cool!
On Aug 25, 7:16 am, dingue fever <dingue.fe...@gmail.com> wrote:
> Hi,
>
> Is it possible to dynamically add fields to a formwizard form. I have
> been able to add the fields I want but if the form fails validation
> the new dynamic fields disappear when the form re-renders. Is it
> possible to override this so that I can validate and return the new
> fields if the validation fails?
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
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