Changeset 6352
- Timestamp:
- 09/15/07 23:38:20 (1 year ago)
- Files:
-
- django/trunk/AUTHORS (modified) (1 diff)
- django/trunk/django/newforms/forms.py (modified) (3 diffs)
- django/trunk/docs/newforms.txt (modified) (1 diff)
- django/trunk/tests/regressiontests/forms/tests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/AUTHORS
r6350 r6352 123 123 Matthew Flanagan <http://wadofstuff.blogspot.com> 124 124 Eric Floehr <eric@intellovations.com> 125 Vincent Foley <vfoleybourgon@yahoo.ca> 125 126 Jorge Gajon <gajon@gajon.org> 126 127 gandalf@owca.info django/trunk/django/newforms/forms.py
r6273 r6352 59 59 # class, not to the Form class. 60 60 def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, 61 initial=None, error_class=ErrorList):61 initial=None, error_class=ErrorList, label_suffix=':'): 62 62 self.is_bound = data is not None or files is not None 63 63 self.data = data or {} … … 67 67 self.initial = initial or {} 68 68 self.error_class = error_class 69 self.label_suffix = label_suffix 69 70 self._errors = None # Stores the errors after clean() has been called. 70 71 … … 130 131 if bf.label: 131 132 label = escape(force_unicode(bf.label)) 132 # Only add a colon if the label does not end in punctuation. 133 if label[-1] not in ':?.!': 134 label += ':' 133 # Only add the suffix if the label does not end in punctuation. 134 if self.label_suffix: 135 if label[-1] not in ':?.!': 136 label += self.label_suffix 135 137 label = bf.label_tag(label) or '' 136 138 else: django/trunk/docs/newforms.txt
r6288 r6352 513 513 514 514 By default, ``auto_id`` is set to the string ``'id_%s'``. 515 516 Normally, a colon (``:``) will be appended after any label name when a form is 517 rendered. It's possible to change the colon to another character, or omit it 518 entirely, using the ``label_suffix`` parameter:: 519 520 >>> f = ContactForm(auto_id='id_for_%s', label_suffix='') 521 >>> print f.as_ul() 522 <li><label for="id_for_subject">Subject</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" /></li> 523 <li><label for="id_for_message">Message</label> <input type="text" name="message" id="id_for_message" /></li> 524 <li><label for="id_for_sender">Sender</label> <input type="text" name="sender" id="id_for_sender" /></li> 525 <li><label for="id_for_cc_myself">Cc myself</label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></li> 526 >>> f = ContactForm(auto_id='id_for_%s', label_suffix=' ->') 527 >>> print f.as_ul() 528 <li><label for="id_for_subject">Subject -></label> <input id="id_for_subject" type="text" name="subject" maxlength="100" /></li> 529 <li><label for="id_for_message">Message -></label> <input type="text" name="message" id="id_for_message" /></li> 530 <li><label for="id_for_sender">Sender -></label> <input type="text" name="sender" id="id_for_sender" /></li> 531 <li><label for="id_for_cc_myself">Cc myself -></label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></li> 532 533 Note that the label suffix is added only if the last character of the 534 label isn't a punctuation character (``.``, ``!``, ``?`` or ``:``) 515 535 516 536 Notes on field ordering django/trunk/tests/regressiontests/forms/tests.py
r6282 r6352 2944 2944 <li><label for="id_password">Password:</label> <input type="password" name="password" id="id_password" /></li> 2945 2945 2946 2947 # Label Suffix ################################################################ 2948 2949 You can specify the 'label_suffix' argument to a Form class to modify the 2950 punctuation symbol used at the end of a label. By default, the colon (:) is 2951 used, and is only appended to the label if the label doesn't already end with a 2952 punctuation symbol: ., !, ? or :. If you specify a different suffix, it will 2953 be appended regardless of the last character of the label. 2954 2955 >>> class FavoriteForm(Form): 2956 ... color = CharField(label='Favorite color?') 2957 ... animal = CharField(label='Favorite animal') 2958 ... 2959 >>> f = FavoriteForm(auto_id=False) 2960 >>> print f.as_ul() 2961 <li>Favorite color? <input type="text" name="color" /></li> 2962 <li>Favorite animal: <input type="text" name="animal" /></li> 2963 >>> f = FavoriteForm(auto_id=False, label_suffix='?') 2964 >>> print f.as_ul() 2965 <li>Favorite color? <input type="text" name="color" /></li> 2966 <li>Favorite animal? <input type="text" name="animal" /></li> 2967 >>> f = FavoriteForm(auto_id=False, label_suffix='') 2968 >>> print f.as_ul() 2969 <li>Favorite color? <input type="text" name="color" /></li> 2970 <li>Favorite animal <input type="text" name="animal" /></li> 2971 >>> f = FavoriteForm(auto_id=False, label_suffix=u'\u2192') 2972 >>> f.as_ul() 2973 u'<li>Favorite color? <input type="text" name="color" /></li>\n<li>Favorite animal\u2192 <input type="text" name="animal" /></li>' 2974 2975 2976 2946 2977 # Initial data ################################################################ 2947 2978
