On 08.04.2009, at 17:10, Facundo Casco wrote:

>
> On Tue, Jan 20, 2009 at 11:17 AM, [email protected]
> <[email protected]> wrote:
>>
>> Thanks guys, I'm gonna give this a try!
>>
>> Mike.
> Hi, I'm having the exact same problem you had and I can't find a nice
> way around it.
> I want the name of the currently logged in user to be pre-selected in
> a combo box in the form.
>
> The form is used to create a new object in the database. What I've
> found as the main problem is that when I display the form for the
> first time, if it's bound it throws validation errors (because I don't
> want to pre-populate all the required fields) and if it is not bound
> it just doesn't display the pre-populated data.
>
> My workaround at the time is to pass a flag to the template so it
> doesn't show the errors but I still don't think that is the best way
> to do it.
>
> Any help would be appreciated.
>

If you create tHe Form ala

form = Form( initial={'user': request.user})

it should prepopulate the field and not throw validation errors.

if on the other hand you create the form like:

form = Form({'user': request.user})

you bind the form and it validates on output.

adi

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to