Ticket #8627: fix_textarea_disappearing_first_empty_line.diff

File fix_textarea_disappearing_first_empty_line.diff, 4.4 KB (added by sebastian.hillig, 16 years ago)

Patch, only adds a line-break, with corrected tests

  • django/forms/widgets.py

     
    282282        if value is None: value = ''
    283283        value = force_unicode(value)
    284284        final_attrs = self.build_attrs(attrs, name=name)
    285         return mark_safe(u'<textarea%s>%s</textarea>' % (flatatt(final_attrs),
     285        return mark_safe(u'<textarea%s>\r\n%s</textarea>' % (flatatt(final_attrs),
    286286                conditional_escape(force_unicode(value))))
    287287
    288288class DateTimeInput(Input):
  • tests/modeltests/model_forms/models.py

     
    350350<option value="1">Mike Royko</option>
    351351<option value="2">Bob Woodward</option>
    352352</select></td></tr>
    353 <tr><th>Article:</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr>
     353<tr><th>Article:</th><td><textarea rows="10" cols="40" name="article">
     354</textarea></td></tr>
    354355<tr><th>Status:</th><td><select name="status">
    355356<option value="" selected="selected">---------</option>
    356357<option value="1">Draft</option>
     
    405406<option value="1" selected="selected">Mike Royko</option>
    406407<option value="2">Bob Woodward</option>
    407408</select></li>
    408 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
     409<li>Article: <textarea rows="10" cols="40" name="article">
     410Hello.</textarea></li>
    409411<li>Status: <select name="status">
    410412<option value="" selected="selected">---------</option>
    411413<option value="1">Draft</option>
     
    466468<option value="1" selected="selected">Mike Royko</option>
    467469<option value="2">Bob Woodward</option>
    468470</select></li>
    469 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
     471<li>Article: <textarea rows="10" cols="40" name="article">
     472Hello.</textarea></li>
    470473<li>Status: <select name="status">
    471474<option value="" selected="selected">---------</option>
    472475<option value="1">Draft</option>
     
    582585<option value="1">Mike Royko</option>
    583586<option value="2">Bob Woodward</option>
    584587</select></li>
    585 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
     588<li>Article: <textarea rows="10" cols="40" name="article">
     589</textarea></li>
    586590<li>Status: <select name="status">
    587591<option value="" selected="selected">---------</option>
    588592<option value="1">Draft</option>
     
    608612<option value="2">Bob Woodward</option>
    609613<option value="3">Carl Bernstein</option>
    610614</select></li>
    611 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
     615<li>Article: <textarea rows="10" cols="40" name="article">
     616</textarea></li>
    612617<li>Status: <select name="status">
    613618<option value="" selected="selected">---------</option>
    614619<option value="1">Draft</option>
  • tests/regressiontests/forms/forms.py

     
    303303>>> print f['subject']
    304304<input type="text" name="subject" />
    305305>>> print f['message']
    306 <textarea rows="10" cols="40" name="message"></textarea>
     306<textarea rows="10" cols="40" name="message">
     307</textarea>
    307308
    308309as_textarea(), as_text() and as_hidden() are shortcuts for changing the output
    309310widget type:
    310311>>> f['subject'].as_textarea()
    311 u'<textarea rows="10" cols="40" name="subject"></textarea>'
     312u'<textarea rows="10" cols="40" name="subject">\r\n</textarea>'
    312313>>> f['message'].as_text()
    313314u'<input type="text" name="message" />'
    314315>>> f['message'].as_hidden()
     
    320321...     message = CharField(widget=Textarea(attrs={'rows': 80, 'cols': 20}))
    321322>>> f = ContactForm(auto_id=False)
    322323>>> print f['message']
    323 <textarea rows="80" cols="20" name="message"></textarea>
     324<textarea rows="80" cols="20" name="message">
     325</textarea>
    324326
    325327Instance-level attrs are *not* carried over to as_textarea(), as_text() and
    326328as_hidden():
     
    328330u'<input type="text" name="message" />'
    329331>>> f = ContactForm({'subject': 'Hello', 'message': 'I love you.'}, auto_id=False)
    330332>>> f['subject'].as_textarea()
    331 u'<textarea rows="10" cols="40" name="subject">Hello</textarea>'
     333u'<textarea rows="10" cols="40" name="subject">\r\nHello</textarea>'
    332334>>> f['message'].as_text()
    333335u'<input type="text" name="message" value="I love you." />'
    334336>>> f['message'].as_hidden()
Back to Top