Re: Add attributes (css-class) to formfield

2011-07-15 Thread Andreas Pfrengle
Tom, it's really so easy, thank you! Seems now I've learned the hard way how forms and fields are working ;-) Andreas -- 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 unsubs

Re: Add attributes (css-class) to formfield

2011-07-14 Thread Tom Evans
On Wed, Jul 13, 2011 at 6:41 PM, Andreas Pfrengle wrote: > Hello, > > I know about assigning attributes to widgets, like shown here: > widget-instances> > or here: >

Re: Add attributes (css-class) to formfield

2011-07-13 Thread Andreas Pfrengle
Hello Andre, it took me some time, but since I couldn't get insight in suggestion 1) and 2) really seemed too ugly, I've discovered an intermediate solution. I came around it when trying to make suggestion 2) a little less ugly, and after all it's still quite easy ;-) 3) Write a template-filter t

Re: Add attributes (css-class) to formfield

2011-07-13 Thread Andre Terra
Shawn, He wants the form attribute to be applied to the div, not the field. Andreas, You can't pass an attribute to a field and expect it to show up in a different object altogether. I assume your div isn't handled by django, so you need to fix that first in order to be able to pass extra attri

Re: Add attributes (css-class) to formfield

2011-07-13 Thread Shawn Milochik
On 07/13/2011 02:00 PM, Andreas Pfrengle wrote: Hello Shawn, thanks for your answer, however that's not exactly what I wanted. Now the html renders to: No. of properties However, I would want: No. of properties Additionally, I can't access {{ field.wid

Re: Add attributes (css-class) to formfield

2011-07-13 Thread Andre Terra
Write a wrapper function and make it even shorter (ok, go ahead and call it syntax sugar): def css(field, **kwargs): field.attrs.update(**kwargs) use as: css(self.fields['release_date'], div_css="test") DISCLAIMER: not tested on a real Field, but I tested it on a simple class in a python sh

Re: Add attributes (css-class) to formfield

2011-07-13 Thread Andreas Pfrengle
Hello Shawn, thanks for your answer, however that's not exactly what I wanted. Now the html renders to: No. of properties However, I would want: No. of properties Additionally, I can't access {{ field.widget.attrs.div_css }} to get the class directly, I get an

Re: Add attributes (css-class) to formfield

2011-07-13 Thread Shawn Milochik
Following this as a sample (from the docs you linked to): widget=forms.TextInput(attrs={'class':'special'})) You'd do this: widget=forms.TextInput(attrs={'div_css':'test'})) Or, to not clobber other things set in the form, you could do it in the __init__: #working example I just

Add attributes (css-class) to formfield

2011-07-13 Thread Andreas Pfrengle
Hello, I know about assigning attributes to widgets, like shown here: or here: However, I want to assign an additional attribute t