On Sat, 2007-05-05 at 23:13 -0700, Joseph Heck wrote:
> A site I frequently work with has the forms mostly laid out using <dl>
> and CSS to style it up all nicely. The newforms doesn't have a as_dl
> method, and my designer is pitching a bit of fit that we can't give
> him the pieces/parts of the form to lay out with a more complex setup.
> 
> When I looked into it, I saw that some patches to generate "as_dl"
> methods on newforms had been turned down. (Fine, we can add that too a
> subclass and work around it). I think I'm missing something about how
> I can hand the layout control to the designer though - telling them to
> just deal with what {{ form.as_ul }} about got my teeth kicked in.
> 
> Is it expected that with any newforms form object you'll be able to
> reference it in the template with something like:
> 
> {% for field in form %}
>   <p>{{ field.label }} {{ field }}</p>
> {% endfor %}

Yes, that should always work.

The key classes to look at in the source are newforms.forms.BoundField
(which is what you are really working with as "field" in the above
sample) and newforms.fields.Field, which is what BoundField wraps up.
Both have fairly useful docstrings in the classes. I guess the various
newforms.widgets.* and newforms.extras.widgets.* classes are of
interest, too.

> 
> And does anyone have some examples where the newforms are worked up to
> any extent in templates? I need to learn what we can do, and I'm
> having a hard time finding many references to using newforms from
> inside of templates.

I don't (what with having all the artistic talent of a clay brick and
all), but once you've worked out your little fragment above, what are
the bits that are still providing difficulties? I appreciate that some
people prefer working from examples, rather than theory, so that may be
the motivation behind your question. However, if there are some parts
that are particularly tricky to work out from looking at a couple of
classes in the source, please point them out.

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