List Info

Thread: newforms: create form with preselected value




newforms: create form with preselected value
user name
2008-01-21 10:23:49
hi,

i'm currently trying to create a form with newforms from a
model. now
i would like to create an add-form where a selection field
shall have
a preselected value. i know that i can pass a
data-dictionary when
instantiating the form:


FolderForm = forms.models.form_for_model(Folder)
form = FolderForm({'parent': id})

If I render this form, i unfortunately get already
validation errors
about the other fields that are missing. Is there a way to
instantiate
and render a Form without validation or perhaps another
possibility to
prefill form fields?

regards,
lowshoe
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: newforms: create form with preselected value
user name
2008-01-21 11:12:27
On Jan 21, 2008 11:23 AM, lowshoe < lowshoegmail.com">lowshoegmail.com> wrote:

hi,

i&#39;m currently trying to create a form with newforms from a model. now
i would like to create an add-form where a selection field shall have
a preselected value. i know that i can pass a data-dictionary when
instantiating the form:


FolderForm = forms.models.form_for_model(Folder)
form = FolderForm({'parent': id})

If I render this form, i unfortunately get already validation errors
about the other fields that are missing. Is there a way to instantiate
and render a Form without validation or perhaps another possibility to
prefill form fields?

Sounds like you want dynamic initial values:

http://www.djangoproject.com/documentation/newforms/#dynamic-initial-values

(You might also want to look at the newer ModelForm instead of form_for_model.)

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users"; group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to django-users-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )