Sunday, August 25, 2013

Single form displayed multiple times on one page with different values.

I have the this simple form:

class MistagForm(forms.Form):
    artist = forms.CharField()

And I want to display it on a page more than once. The page is a list of artists, and each artist has a link to the above form that will be a popup form.

I want the default value of artist in the form to show as the actual name of the artist, so each instance of the form will be bound to a different artist name.

I can't figure out a way in the template to set the value of the artist input field to the name of each different artist. I don't think that setting the initial values of the form(s) in the view would work, as there can be hundreds of artists on a page.

I need something like {{form.artist|default:model.artist}} but I know from research (and trying) that this does not work.

I didn't mention that the popup forms are generated when the page loads, not when the link to the popup is clicked. (they are hidden until the link is clicked)

And I'm avoiding the use of the javascript virus :-D

Thanks for any pointers!
Brian

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate