On Wed, 2009-01-21 at 21:41 -0800, Lee wrote:
> Hi, everyone.
> 
> I have some trouble in SelectMultiple Widget. The detailed information
> is that:
> 
> In the form.py, I have defined a TestForm which contain a
> SelectMultiple Widget called selection
> 
> #form.py
> class TestForm(forms.Form):
>   selection = forms.CharField( widget=forms.SelectMultiple() )
> 
> Howvever, if I want to assign values to that widget, how to do that in
> the views.py?

If you want to assign the choices will appear in the HTML form, assign
to self.fields["selection"].choices in the __init__ method of the form.
See [1] for a recent thread on that (scroll down to the end of the
thread, because it starts at as a "how do I...?" question and the answer
is only in one of the final posts).

If you want to set up the initial selection values, pass in an "initial"
parameter when you construct the form. See [2] (the Django docs for
that) and [3] (another recent thread about setting initial values on
multi-select stuff -- I don't know why it only shows my replies and not
the original poster, but the info is there).

[1]
http://groups.google.com/group/django-users/browse_frm/thread/b4dadbc8a8ad6011/4e745c2419f00289?tvc=1#

[2]
http://docs.djangoproject.com/en/dev/ref/forms/fields/#dynamic-initial-values

[3]
http://groups.google.com/group/django-users/browse_frm/thread/2d5595d28afbee46?tvc=1

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
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