Ticket #3686: required_label.diff

File required_label.diff, 2.1 KB (added by ramzes@…, 18 years ago)
  • django/newforms/forms.py

     
    121121            else:
    122122                if errors_on_separate_row and bf_errors:
    123123                    output.append(error_row % bf_errors)
    124                 label = bf.label and bf.label_tag(escape(bf.label + ':')) or ''
     124                attrs = field.required and {'class': 'required'} or None
     125                label = bf.label and bf.label_tag(escape(bf.label + ':'), attrs=attrs) or ''
    125126                if field.help_text:
    126127                    help_text = help_text_html % field.help_text
    127128                else:
  • tests/modeltests/model_forms/models.py

     
    7171>>> CategoryForm = form_for_model(Category)
    7272>>> f = CategoryForm()
    7373>>> print f
    74 <tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="20" /></td></tr>
    75 <tr><th><label for="id_url">The URL:</label></th><td><input id="id_url" type="text" name="url" maxlength="40" /></td></tr>
     74<tr><th><label for="id_name" class="required">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="20" /></td></tr>
     75<tr><th><label for="id_url" class="required">The URL:</label></th><td><input id="id_url" type="text" name="url" maxlength="40" /></td></tr>
    7676>>> print f.as_ul()
    77 <li><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" maxlength="20" /></li>
    78 <li><label for="id_url">The URL:</label> <input id="id_url" type="text" name="url" maxlength="40" /></li>
     77<li><label for="id_name" class="required">Name:</label> <input id="id_name" type="text" name="name" maxlength="20" /></li>
     78<li><label for="id_url" class="required">The URL:</label> <input id="id_url" type="text" name="url" maxlength="40" /></li>
    7979>>> print f['name']
    8080<input id="id_name" type="text" name="name" maxlength="20" />
    8181
Back to Top