Re: Let Django form render field's with custom attributes (e.g CSS)?

2010-03-26 Thread Thierry
Thanks for the feedbacks.
And yes unfortunately I am bound to support our "official corporate
browser" IE6, otherwise I would have happily gone to a more CSS-only
direction.
What puzzles me most is that method BoundField.label_tag() has an
attr(ibute)s argument and some code to support it, but there is no
easy way to call it (unable to pass arguments to methods in
templates).

For the time being, I will go with my initial idea (subclassing my own
Widget/Renderer classes to provide  rendering with custom css),
leaving Field's  HTML definition as is.

I would however appreciate easy/lazy ways to customize attributes on a
Field's , e.g for common CSS patterns where the 
automatically gets "required" or "error" CSS classes depending on the
Field's validation options.

On 26 mar, 15:28, David De La Harpe Golden
 wrote:
> On 26/03/10 13:18, Thierry wrote:
>
> > Hi,
>
> > I want to differentiate CSS style of fields  from the style of
> > RadioSelects  elements (as rendered through
> > RadioFieldRenderer).
> > Immediate action: I could create my RadioFieldRenderer/RadioInput
> > classes to display inner labels as.
>
> > Any direction you could give me? Thanks in advance.
>
> Well, not a general solution for element attributes, but do bear in mind
> that css selectors (and jquery's selectors for that matter) can be a bit
> more than just the basic "element" ".class" and "#id" that you always see.
>
> See e.g.http://www.w3.org/TR/css3-selectors/(or css2)
>
> So, you can style django's simple builtin form outputs somewhat more
> aggressively than you might realise if you're not up on css, without
> having to subclass to override outputs, if you _wrap_ the output in
> something for css to match.  [If your requirements include "support
> ancient versions of MSIE" you might find said ancient versions' css
> handling a bit annoying though]
>
> Vague example:
>
> 
>    
>      
>        div.form_wrapper > label { background-color: #ff }
>        div.form_wrapper label { color: #ff }
>        div.form_wrapper > label:first-child { color: #00ff00 }
>        div.form_wrapper > label:nth-child(3) { color: #00 }
>      
>    
>    
>    
>      FOO
>      
>        BAR
>      
>      BAZ
>      MOO
>    
>    
> 

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



Re: Let Django form render field's with custom attributes (e.g CSS)?

2010-03-26 Thread David De La Harpe Golden

On 26/03/10 13:18, Thierry wrote:

Hi,

I want to differentiate CSS style of fields  from the style of
RadioSelects  elements (as rendered through
RadioFieldRenderer).
Immediate action: I could create my RadioFieldRenderer/RadioInput
classes to display inner labels as.




Any direction you could give me? Thanks in advance.



Well, not a general solution for element attributes, but do bear in mind 
that css selectors (and jquery's selectors for that matter) can be a bit 
more than just the basic "element" ".class" and "#id" that you always see.


See e.g. http://www.w3.org/TR/css3-selectors/ (or css2)

So, you can style django's simple builtin form outputs somewhat more 
aggressively than you might realise if you're not up on css, without 
having to subclass to override outputs, if you _wrap_ the output in 
something for css to match.  [If your requirements include "support 
ancient versions of MSIE" you might find said ancient versions' css 
handling a bit annoying though]


Vague example:


  

  div.form_wrapper > label { background-color: #ff }
  div.form_wrapper label { color: #ff }
  div.form_wrapper > label:first-child { color: #00ff00 }
  div.form_wrapper > label:nth-child(3) { color: #00 }

  
  
  
FOO

  BAR

BAZ
MOO
  
  









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



Re: Let Django form render field's with custom attributes (e.g CSS)?

2010-03-26 Thread Xavier Ordoquy
Hello,

I believe {{form.as_ul}} is for prototypes but once you get deeper into the 
project you most probably want to throw it, only use {{form.field}} and define 
label in html within your template.

Xavier.

Le 26 mars 2010 à 14:18, Thierry a écrit :

> Hi,
> 
> I want to differentiate CSS style of fields  from the style of
> RadioSelects  elements (as rendered through
> RadioFieldRenderer).
> Immediate action: I could create my RadioFieldRenderer/RadioInput
> classes to display inner labels as .
> 
> But (and this is mostly my point of raising the issue), I was also
> looking at a way to provide attributes (CSS classes, inline style, id,
> etc) to the  element rendered directly by Django (though
> {{form.as_ul}} or {{field.label_tag}} for instance).
> 
> Digging the code, I found the BoundField class with its method
> label_tag. Problems:
> - this method is either called from form.as_ul() (or as_p(), etc)
> without passing attrs parameters
> - or it can be called directly from a template
> ({{myfield.label_tag}}), but without the ability to pass extra
> arguments.
> 
> Basically I am stuck wondering how to set attributes on a Field's
> rendered label, without having to hardcode it in every form template,
> or subclassing the whole Form/BoundField classes...
> 
> Any direction you could give me? Thanks in advance.
> 
> -- 
> 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.
> 

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



Let Django form render field's with custom attributes (e.g CSS)?

2010-03-26 Thread Thierry
Hi,

I want to differentiate CSS style of fields  from the style of
RadioSelects  elements (as rendered through
RadioFieldRenderer).
Immediate action: I could create my RadioFieldRenderer/RadioInput
classes to display inner labels as .

But (and this is mostly my point of raising the issue), I was also
looking at a way to provide attributes (CSS classes, inline style, id,
etc) to the  element rendered directly by Django (though
{{form.as_ul}} or {{field.label_tag}} for instance).

Digging the code, I found the BoundField class with its method
label_tag. Problems:
- this method is either called from form.as_ul() (or as_p(), etc)
without passing attrs parameters
- or it can be called directly from a template
({{myfield.label_tag}}), but without the ability to pass extra
arguments.

Basically I am stuck wondering how to set attributes on a Field's
rendered label, without having to hardcode it in every form template,
or subclassing the whole Form/BoundField classes...

Any direction you could give me? Thanks in advance.

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