#3512: [patch] Add HTML classes to fields in newforms as_methods: "required" &
"error"
-------------------------------------------------+--------------------------
   Reporter:  Waylan Limberg <[EMAIL PROTECTED]>  |                Owner:  
adrian                
     Status:  new                                |            Component:  
django.newforms       
    Version:  SVN                                |           Resolution:        
                
   Keywords:                                     |                Stage:  
Design decision needed
  Has_patch:  1                                  |           Needs_docs:  0     
                
Needs_tests:  0                                  |   Needs_better_patch:  0     
                
-------------------------------------------------+--------------------------
Comment (by Waylan Limberg <[EMAIL PROTECTED]>):

 For those who aren't using the as_methods(), you can still check if a
 field is required in the template, much like you can check that a field
 has errors:
 
 {{{
 {% for boundfield in form %}
     {% if boundfield.errors %}
     do stuff...
     {% endif %}
 
     {% if boundfield.field.required %}
     do stuff...
     {% endif %}
 {% endfor %}
 }}}
 
 We could always add a 'required' property to the !BoundField class, but
 why? Here it is anyway (Allowing one to do `{% if boundfield.required %}`
 ):
 
 
 {{{
 def _required(self):
     "Returns True if this BoundField is required."
     return self.field.required
 required = property(_required)
 }}}
 
 Whether that little patch is applied or not, those of you building your
 own forms can generate whatever html you want without any additional
 patches and that is why this patch only affects the as_methods(). Yes, if
 you want a class attribute on a field element itself, you have to manually
 build the entire field element (with `boundfield.name`, `boundfield.data`,
 `boundfield.label` etc) but isn't that the way it should be for those who
 want such fine grained control as to assign custom classes to individual
 elements in the templates?
 
 Note: I'm posting this partially as a note to myself. I figured this all
 out a month ago when I wrote the patches, but promptly forgot. Following
 the above discussion, I dug in again only to realize I was repeating
 myself. D'oh.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/3512#comment:15>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to