Ticket #3929: textarea_validity.patch

File textarea_validity.patch, 6.0 KB (added by Luke Plant, 17 years ago)

Patch for textarea output and corresponding tests

  • django/newforms/widgets.py

     
    121121    input_type = 'file'
    122122
    123123class Textarea(Widget):
     124    def __init__(self, attrs=None):
     125        self.attrs = {'cols': '40', 'rows': '10'} # Needed for HTML correctness
     126        if attrs:
     127            self.attrs.update(attrs)
     128
    124129    def render(self, name, value, attrs=None):
    125130        if value is None: value = ''
    126131        value = smart_unicode(value)
  • tests/modeltests/model_forms/models.py

     
    159159<option value="1">Mike Royko</option>
    160160<option value="2">Bob Woodward</option>
    161161</select></td></tr>
    162 <tr><th>Article:</th><td><textarea name="article"></textarea></td></tr>
     162<tr><th>Article:</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr>
    163163<tr><th>Categories:</th><td><select multiple="multiple" name="categories">
    164164<option value="1">Entertainment</option>
    165165<option value="2">It&#39;s a test</option>
     
    199199<option value="1" selected="selected">Mike Royko</option>
    200200<option value="2">Bob Woodward</option>
    201201</select></li>
    202 <li>Article: <textarea name="article">Hello.</textarea></li>
     202<li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
    203203<li>Categories: <select multiple="multiple" name="categories">
    204204<option value="1">Entertainment</option>
    205205<option value="2">It&#39;s a test</option>
     
    231231<option value="1" selected="selected">Mike Royko</option>
    232232<option value="2">Bob Woodward</option>
    233233</select></li>
    234 <li>Article: <textarea name="article">Hello.</textarea></li>
     234<li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
    235235<li>Categories: <select multiple="multiple" name="categories">
    236236<option value="1" selected="selected">Entertainment</option>
    237237<option value="2">It&#39;s a test</option>
     
    309309<option value="1">Mike Royko</option>
    310310<option value="2">Bob Woodward</option>
    311311</select></li>
    312 <li>Article: <textarea name="article"></textarea></li>
     312<li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
    313313<li>Categories: <select multiple="multiple" name="categories">
    314314<option value="1">Entertainment</option>
    315315<option value="2">It&#39;s a test</option>
     
    328328<option value="2">Bob Woodward</option>
    329329<option value="3">Carl Bernstein</option>
    330330</select></li>
    331 <li>Article: <textarea name="article"></textarea></li>
     331<li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
    332332<li>Categories: <select multiple="multiple" name="categories">
    333333<option value="1">Entertainment</option>
    334334<option value="2">It&#39;s a test</option>
  • tests/regressiontests/forms/tests.py

     
    193193
    194194>>> w = Textarea()
    195195>>> w.render('msg', '')
    196 u'<textarea name="msg"></textarea>'
     196u'<textarea rows="10" cols="40" name="msg"></textarea>'
    197197>>> w.render('msg', None)
    198 u'<textarea name="msg"></textarea>'
     198u'<textarea rows="10" cols="40" name="msg"></textarea>'
    199199>>> w.render('msg', 'value')
    200 u'<textarea name="msg">value</textarea>'
     200u'<textarea rows="10" cols="40" name="msg">value</textarea>'
    201201>>> w.render('msg', 'some "quoted" & ampersanded value')
    202 u'<textarea name="msg">some &quot;quoted&quot; &amp; ampersanded value</textarea>'
    203 >>> w.render('msg', 'value', attrs={'class': 'pretty'})
    204 u'<textarea name="msg" class="pretty">value</textarea>'
     202u'<textarea rows="10" cols="40" name="msg">some &quot;quoted&quot; &amp; ampersanded value</textarea>'
     203>>> w.render('msg', 'value', attrs={'class': 'pretty', 'rows': 20})
     204u'<textarea class="pretty" rows="20" cols="40" name="msg">value</textarea>'
    205205
    206206You can also pass 'attrs' to the constructor:
    207207>>> w = Textarea(attrs={'class': 'pretty'})
    208208>>> w.render('msg', '')
    209 u'<textarea class="pretty" name="msg"></textarea>'
     209u'<textarea rows="10" cols="40" name="msg" class="pretty"></textarea>'
    210210>>> w.render('msg', 'example')
    211 u'<textarea class="pretty" name="msg">example</textarea>'
     211u'<textarea rows="10" cols="40" name="msg" class="pretty">example</textarea>'
    212212
    213213'attrs' passed to render() get precedence over those passed to the constructor:
    214214>>> w = Textarea(attrs={'class': 'pretty'})
    215215>>> w.render('msg', '', attrs={'class': 'special'})
    216 u'<textarea class="special" name="msg"></textarea>'
     216u'<textarea rows="10" cols="40" name="msg" class="special"></textarea>'
    217217
    218218>>> w.render('msg', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'})
    219 u'<textarea class="fun" name="msg">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</textarea>'
     219u'<textarea rows="10" cols="40" name="msg" class="fun">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</textarea>'
    220220
    221221# CheckboxInput Widget ########################################################
    222222
     
    19661966>>> print f['subject']
    19671967<input type="text" name="subject" />
    19681968>>> print f['message']
    1969 <textarea name="message"></textarea>
     1969<textarea rows="10" cols="40" name="message"></textarea>
    19701970
    19711971as_textarea(), as_text() and as_hidden() are shortcuts for changing the output
    19721972widget type:
    19731973>>> f['subject'].as_textarea()
    1974 u'<textarea name="subject"></textarea>'
     1974u'<textarea rows="10" cols="40" name="subject"></textarea>'
    19751975>>> f['message'].as_text()
    19761976u'<input type="text" name="message" />'
    19771977>>> f['message'].as_hidden()
     
    19911991u'<input type="text" name="message" />'
    19921992>>> f = ContactForm({'subject': 'Hello', 'message': 'I love you.'}, auto_id=False)
    19931993>>> f['subject'].as_textarea()
    1994 u'<textarea name="subject">Hello</textarea>'
     1994u'<textarea rows="10" cols="40" name="subject">Hello</textarea>'
    19951995>>> f['message'].as_text()
    19961996u'<input type="text" name="message" value="I love you." />'
    19971997>>> f['message'].as_hidden()
Back to Top