jquery, json and forms

40 views
Skip to first unread message

David

unread,
Jul 2, 2012, 11:12:49 AM7/2/12
to django...@googlegroups.com
Hello

I have a form that saves, and displays errors correctly when using javascript and without.

However, when my form saves I need to refresh the form with the new form data. How can I pass the form object through json back to my template please?

Thank you for any help.

Jon Black

unread,
Jul 2, 2012, 11:46:07 AM7/2/12
to django...@googlegroups.com
One approach is to pass json/html data in the response after saving and
use jQuery to update the page.
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/83FaoYuJjFQJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.


signature.asc

Psamathos

unread,
Jul 2, 2012, 12:37:44 PM7/2/12
to django...@googlegroups.com
It sounds like you want to initialize your form in the view. You can also do this by passing an initial keyword argument to the form constructor:

    exampleform = ExampleForm(initial={"examplefield": request.user.first_name})


This would set the examplefield of ExampleForm to the requesting user's first name.
Reply all
Reply to author
Forward
0 new messages