On Sun, Nov 29, 2009 at 9:52 AM, Gloria <strang...@comcast.net> wrote:

> Thanks for the response. I am trying to do this on the server side.
> Here is more detail.
> I am initializing it to all unchecked checkboxes in my forms.py.
> Then, in my view, I am trying to have HTML generate a "checked" value
> for certain checkboxes, based on some user data I received in that
> view.
> How do I generate "checked" HTML option using the builtin
> ModelMultipleChoiceField for certain checkboxes? Is there a builtin
> option that I  should set manually to cause the "checked" option to be
> generated? Or do I have to iterate over these fields, match them with
> data I have received, and generate the "checked" option myself, in the
> template?
>
>
You shouldn't have to do that if the data is available in your view.  It
should be as easy as passing a dict as "initial" to your form instance you
create in the view:

form = MyForm(initial = {"foo"=True, "bar"=True}

with the field names (instead of foo and bar) of the check boxes you want
checked.  Your form then should have them checked when it is rendered.

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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