Ticket #3929: textarea_validity.patch
File textarea_validity.patch, 6.0 KB (added by , 18 years ago) |
---|
-
django/newforms/widgets.py
121 121 input_type = 'file' 122 122 123 123 class 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 124 129 def render(self, name, value, attrs=None): 125 130 if value is None: value = '' 126 131 value = smart_unicode(value) -
tests/modeltests/model_forms/models.py
159 159 <option value="1">Mike Royko</option> 160 160 <option value="2">Bob Woodward</option> 161 161 </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> 163 163 <tr><th>Categories:</th><td><select multiple="multiple" name="categories"> 164 164 <option value="1">Entertainment</option> 165 165 <option value="2">It's a test</option> … … 199 199 <option value="1" selected="selected">Mike Royko</option> 200 200 <option value="2">Bob Woodward</option> 201 201 </select></li> 202 <li>Article: <textarea name="article">Hello.</textarea></li>202 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li> 203 203 <li>Categories: <select multiple="multiple" name="categories"> 204 204 <option value="1">Entertainment</option> 205 205 <option value="2">It's a test</option> … … 231 231 <option value="1" selected="selected">Mike Royko</option> 232 232 <option value="2">Bob Woodward</option> 233 233 </select></li> 234 <li>Article: <textarea name="article">Hello.</textarea></li>234 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li> 235 235 <li>Categories: <select multiple="multiple" name="categories"> 236 236 <option value="1" selected="selected">Entertainment</option> 237 237 <option value="2">It's a test</option> … … 309 309 <option value="1">Mike Royko</option> 310 310 <option value="2">Bob Woodward</option> 311 311 </select></li> 312 <li>Article: <textarea name="article"></textarea></li>312 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li> 313 313 <li>Categories: <select multiple="multiple" name="categories"> 314 314 <option value="1">Entertainment</option> 315 315 <option value="2">It's a test</option> … … 328 328 <option value="2">Bob Woodward</option> 329 329 <option value="3">Carl Bernstein</option> 330 330 </select></li> 331 <li>Article: <textarea name="article"></textarea></li>331 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li> 332 332 <li>Categories: <select multiple="multiple" name="categories"> 333 333 <option value="1">Entertainment</option> 334 334 <option value="2">It's a test</option> -
tests/regressiontests/forms/tests.py
193 193 194 194 >>> w = Textarea() 195 195 >>> w.render('msg', '') 196 u'<textarea name="msg"></textarea>'196 u'<textarea rows="10" cols="40" name="msg"></textarea>' 197 197 >>> w.render('msg', None) 198 u'<textarea name="msg"></textarea>'198 u'<textarea rows="10" cols="40" name="msg"></textarea>' 199 199 >>> w.render('msg', 'value') 200 u'<textarea name="msg">value</textarea>'200 u'<textarea rows="10" cols="40" name="msg">value</textarea>' 201 201 >>> w.render('msg', 'some "quoted" & ampersanded value') 202 u'<textarea name="msg">some "quoted" & ampersanded value</textarea>'203 >>> w.render('msg', 'value', attrs={'class': 'pretty' })204 u'<textarea name="msg" class="pretty">value</textarea>'202 u'<textarea rows="10" cols="40" name="msg">some "quoted" & ampersanded value</textarea>' 203 >>> w.render('msg', 'value', attrs={'class': 'pretty', 'rows': 20}) 204 u'<textarea class="pretty" rows="20" cols="40" name="msg">value</textarea>' 205 205 206 206 You can also pass 'attrs' to the constructor: 207 207 >>> w = Textarea(attrs={'class': 'pretty'}) 208 208 >>> w.render('msg', '') 209 u'<textarea class="pretty" name="msg"></textarea>'209 u'<textarea rows="10" cols="40" name="msg" class="pretty"></textarea>' 210 210 >>> w.render('msg', 'example') 211 u'<textarea class="pretty" name="msg">example</textarea>'211 u'<textarea rows="10" cols="40" name="msg" class="pretty">example</textarea>' 212 212 213 213 'attrs' passed to render() get precedence over those passed to the constructor: 214 214 >>> w = Textarea(attrs={'class': 'pretty'}) 215 215 >>> w.render('msg', '', attrs={'class': 'special'}) 216 u'<textarea class="special" name="msg"></textarea>'216 u'<textarea rows="10" cols="40" name="msg" class="special"></textarea>' 217 217 218 218 >>> w.render('msg', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}) 219 u'<textarea class="fun" name="msg">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</textarea>'219 u'<textarea rows="10" cols="40" name="msg" class="fun">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</textarea>' 220 220 221 221 # CheckboxInput Widget ######################################################## 222 222 … … 1966 1966 >>> print f['subject'] 1967 1967 <input type="text" name="subject" /> 1968 1968 >>> print f['message'] 1969 <textarea name="message"></textarea>1969 <textarea rows="10" cols="40" name="message"></textarea> 1970 1970 1971 1971 as_textarea(), as_text() and as_hidden() are shortcuts for changing the output 1972 1972 widget type: 1973 1973 >>> f['subject'].as_textarea() 1974 u'<textarea name="subject"></textarea>'1974 u'<textarea rows="10" cols="40" name="subject"></textarea>' 1975 1975 >>> f['message'].as_text() 1976 1976 u'<input type="text" name="message" />' 1977 1977 >>> f['message'].as_hidden() … … 1991 1991 u'<input type="text" name="message" />' 1992 1992 >>> f = ContactForm({'subject': 'Hello', 'message': 'I love you.'}, auto_id=False) 1993 1993 >>> f['subject'].as_textarea() 1994 u'<textarea name="subject">Hello</textarea>'1994 u'<textarea rows="10" cols="40" name="subject">Hello</textarea>' 1995 1995 >>> f['message'].as_text() 1996 1996 u'<input type="text" name="message" value="I love you." />' 1997 1997 >>> f['message'].as_hidden()