Friday, July 27, 2012

Re: How is the label_tag's attrs parameter supposed to specified?

A filter that takes a label_tag isn't a bad solution:

@register.filter(is_safe=True)
def label_with_classes(value, arg):

return value.label_tag(attrs={'class': arg})

And then, in the template:

{{ form.my_field|label_with_classes:"class1 class2"}}

On Fri, Jul 20, 2012 at 11:52 AM, Tomas Neme <lacrymology@gmail.com> wrote:
> {% for field in form %}
> <label for="{{ field.id_for_tag }}" foo="bar">{{ field.label
> }}</label>{{ field }}
> {% endfor %}
>
> although I think the custom form class is not such a bad solution
>
>
>
> --
> "The whole of Japan is pure invention. There is no such country, there
> are no such people" --Oscar Wilde
>
> |_|0|_|
> |_|_|0|
> |0|0|0|
>
> (\__/)
> (='.'=)This is Bunny. Copy and paste bunny
> (")_(") to help him gain world domination.
>
> --
> 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+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment