#29153: add label attrs to BaseForm
------------------------------+--------------------------------------
     Reporter:  ChristophRob  |                    Owner:  nobody
         Type:  New feature   |                   Status:  new
    Component:  Forms         |                  Version:  2.0
     Severity:  Normal        |               Resolution:
     Keywords:                |             Triage Stage:  Unreviewed
    Has patch:  0             |      Needs documentation:  0
  Needs tests:  0             |  Patch needs improvement:  0
Easy pickings:  0             |                    UI/UX:  0
------------------------------+--------------------------------------
Description changed by ChristophRob:

Old description:

> As the label_tag is already set up to give the label class attributes and
> label_suffix, it is quite easy to add this to the BaseForm _html_output()
>
> {{{
> class BoundField:
>     def label_tag(self, contents=None, attrs=None, label_suffix=None):
> }}}
>

> {{{
> class BaseForm:
>     def _html_output(self, normal_row, error_row, row_ender,
> help_text_html, errors_on_separate_row):
>         # ...
>         label = bf.label_tag(label) or ''
> }}}

New description:

 Goal:
 Add attributes like "class" to the label tag for inputs.

 Problem:
 Actually the only thing thats stops me from using {{ form }} is the
 incapability to change classes for labels easily. So i have to do it like
 this, for every form and every field:

 {{{
 {{ form.non_field_errors }}
 <div class="fieldWrapper">
     {{ form.subject.errors }}
     <label for="{{ form.subject.id_for_label }}" class="MY-CUSTOM-
 CLASS">Email subject:</label>
     {{ form.subject }}
 </div>

 }}}

 Where it should be changed:
 I would be fine if the label_attrs could be set in BaseForm(), but i think
 the right place would be class Field

 As the label_tag is already set up to give the label class attributes and
 label_suffix, it is quite easy to add this to the BaseForm _html_output()

 {{{
 class BoundField:
     def label_tag(self, contents=None, attrs=None, label_suffix=None):
 }}}


 {{{
 class BaseForm:
     def _html_output(self, normal_row, error_row, row_ender,
 help_text_html, errors_on_separate_row):
         # ...
         label = bf.label_tag(label) or ''
 }}}

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29153#comment:2>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/070.35b8a940cd47219814ed89f6f744c240%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to