Ticket #4975: label_colon_removal.patch
| File label_colon_removal.patch, 90.3 kB (added by gnuvince, 1 year ago) |
|---|
-
django/newforms/forms.py
old new 129 129 output.append(error_row % force_unicode(bf_errors)) 130 130 if bf.label: 131 131 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 += ':'135 132 label = bf.label_tag(label) or '' 136 133 else: 137 134 label = '' -
tests/modeltests/model_forms/models.py
old new 80 80 >>> CategoryForm = form_for_model(Category) 81 81 >>> f = CategoryForm() 82 82 >>> print f 83 <tr><th><label for="id_name">Name :</label></th><td><input id="id_name" type="text" name="name" maxlength="20" /></td></tr>84 <tr><th><label for="id_slug">Slug :</label></th><td><input id="id_slug" type="text" name="slug" maxlength="20" /></td></tr>85 <tr><th><label for="id_url">The URL :</label></th><td><input id="id_url" type="text" name="url" maxlength="40" /></td></tr>83 <tr><th><label for="id_name">Name</label></th><td><input id="id_name" type="text" name="name" maxlength="20" /></td></tr> 84 <tr><th><label for="id_slug">Slug</label></th><td><input id="id_slug" type="text" name="slug" maxlength="20" /></td></tr> 85 <tr><th><label for="id_url">The URL</label></th><td><input id="id_url" type="text" name="url" maxlength="40" /></td></tr> 86 86 >>> print f.as_ul() 87 <li><label for="id_name">Name :</label> <input id="id_name" type="text" name="name" maxlength="20" /></li>88 <li><label for="id_slug">Slug :</label> <input id="id_slug" type="text" name="slug" maxlength="20" /></li>89 <li><label for="id_url">The URL :</label> <input id="id_url" type="text" name="url" maxlength="40" /></li>87 <li><label for="id_name">Name</label> <input id="id_name" type="text" name="name" maxlength="20" /></li> 88 <li><label for="id_slug">Slug</label> <input id="id_slug" type="text" name="slug" maxlength="20" /></li> 89 <li><label for="id_url">The URL</label> <input id="id_url" type="text" name="url" maxlength="40" /></li> 90 90 >>> print f['name'] 91 91 <input id="id_name" type="text" name="name" maxlength="20" /> 92 92 93 93 >>> f = CategoryForm(auto_id=False) 94 94 >>> print f.as_ul() 95 <li>Name :<input type="text" name="name" maxlength="20" /></li>96 <li>Slug :<input type="text" name="slug" maxlength="20" /></li>97 <li>The URL :<input type="text" name="url" maxlength="40" /></li>95 <li>Name <input type="text" name="name" maxlength="20" /></li> 96 <li>Slug <input type="text" name="slug" maxlength="20" /></li> 97 <li>The URL <input type="text" name="url" maxlength="40" /></li> 98 98 99 99 >>> f = CategoryForm({'name': 'Entertainment', 'slug': 'entertainment', 'url': 'entertainment'}) 100 100 >>> f.is_valid() … … 164 164 >>> ArticleForm = form_for_model(Article) 165 165 >>> f = ArticleForm(auto_id=False) 166 166 >>> print f 167 <tr><th>Headline :</th><td><input type="text" name="headline" maxlength="50" /></td></tr>168 <tr><th>Slug :</th><td><input type="text" name="slug" maxlength="50" /></td></tr>169 <tr><th>Pub date :</th><td><input type="text" name="pub_date" /></td></tr>170 <tr><th>Writer :</th><td><select name="writer">167 <tr><th>Headline</th><td><input type="text" name="headline" maxlength="50" /></td></tr> 168 <tr><th>Slug</th><td><input type="text" name="slug" maxlength="50" /></td></tr> 169 <tr><th>Pub date</th><td><input type="text" name="pub_date" /></td></tr> 170 <tr><th>Writer</th><td><select name="writer"> 171 171 <option value="" selected="selected">---------</option> 172 172 <option value="1">Mike Royko</option> 173 173 <option value="2">Bob Woodward</option> 174 174 </select></td></tr> 175 <tr><th>Article :</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr>176 <tr><th>Status :</th><td><select name="status">175 <tr><th>Article</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr> 176 <tr><th>Status</th><td><select name="status"> 177 177 <option value="" selected="selected">---------</option> 178 178 <option value="1">Draft</option> 179 179 <option value="2">Pending</option> 180 180 <option value="3">Live</option> 181 181 </select></td></tr> 182 <tr><th>Categories :</th><td><select multiple="multiple" name="categories">182 <tr><th>Categories</th><td><select multiple="multiple" name="categories"> 183 183 <option value="1">Entertainment</option> 184 184 <option value="2">It's a test</option> 185 185 <option value="3">Third test</option> … … 194 194 >>> PartialArticleForm = form_for_model(Article, fields=('headline','pub_date')) 195 195 >>> f = PartialArticleForm(auto_id=False) 196 196 >>> print f 197 <tr><th>Headline :</th><td><input type="text" name="headline" maxlength="50" /></td></tr>198 <tr><th>Pub date :</th><td><input type="text" name="pub_date" /></td></tr>197 <tr><th>Headline</th><td><input type="text" name="headline" maxlength="50" /></td></tr> 198 <tr><th>Pub date</th><td><input type="text" name="pub_date" /></td></tr> 199 199 200 200 You can pass a custom Form class to form_for_model. Make sure it's a 201 201 subclass of BaseForm, not Form. … … 214 214 >>> RoykoForm = form_for_instance(w) 215 215 >>> f = RoykoForm(auto_id=False) 216 216 >>> print f 217 <tr><th>Name :</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br />Use both first and last names.</td></tr>217 <tr><th>Name</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br />Use both first and last names.</td></tr> 218 218 219 219 >>> art = Article(headline='Test article', slug='test-article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.') 220 220 >>> art.save() … … 223 223 >>> TestArticleForm = form_for_instance(art) 224 224 >>> f = TestArticleForm(auto_id=False) 225 225 >>> print f.as_ul() 226 <li>Headline :<input type="text" name="headline" value="Test article" maxlength="50" /></li>227 <li>Slug :<input type="text" name="slug" value="test-article" maxlength="50" /></li>228 <li>Pub date :<input type="text" name="pub_date" value="1988-01-04" /></li>229 <li>Writer :<select name="writer">226 <li>Headline <input type="text" name="headline" value="Test article" maxlength="50" /></li> 227 <li>Slug <input type="text" name="slug" value="test-article" maxlength="50" /></li> 228 <li>Pub date <input type="text" name="pub_date" value="1988-01-04" /></li> 229 <li>Writer <select name="writer"> 230 230 <option value="">---------</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 rows="10" cols="40" name="article">Hello.</textarea></li>235 <li>Status :<select name="status">234 <li>Article <textarea rows="10" cols="40" name="article">Hello.</textarea></li> 235 <li>Status <select name="status"> 236 236 <option value="" selected="selected">---------</option> 237 237 <option value="1">Draft</option> 238 238 <option value="2">Pending</option> 239 239 <option value="3">Live</option> 240 240 </select></li> 241 <li>Categories :<select multiple="multiple" name="categories">241 <li>Categories <select multiple="multiple" name="categories"> 242 242 <option value="1">Entertainment</option> 243 243 <option value="2">It's a test</option> 244 244 <option value="3">Third test</option> … … 258 258 >>> PartialArticleForm = form_for_instance(art, fields=('headline', 'slug', 'pub_date')) 259 259 >>> f = PartialArticleForm({'headline': u'New headline', 'slug': 'new-headline', 'pub_date': u'1988-01-04'}, auto_id=False) 260 260 >>> print f.as_ul() 261 <li>Headline :<input type="text" name="headline" value="New headline" maxlength="50" /></li>262 <li>Slug :<input type="text" name="slug" value="new-headline" maxlength="50" /></li>263 <li>Pub date :<input type="text" name="pub_date" value="1988-01-04" /></li>261 <li>Headline <input type="text" name="headline" value="New headline" maxlength="50" /></li> 262 <li>Slug <input type="text" name="slug" value="new-headline" maxlength="50" /></li> 263 <li>Pub date <input type="text" name="pub_date" value="1988-01-04" /></li> 264 264 >>> f.is_valid() 265 265 True 266 266 >>> new_art = f.save() … … 279 279 >>> TestArticleForm = form_for_instance(new_art) 280 280 >>> f = TestArticleForm(auto_id=False) 281 281 >>> print f.as_ul() 282 <li>Headline :<input type="text" name="headline" value="New headline" maxlength="50" /></li>283 <li>Slug :<input type="text" name="slug" value="new-headline" maxlength="50" /></li>284 <li>Pub date :<input type="text" name="pub_date" value="1988-01-04" /></li>285 <li>Writer :<select name="writer">282 <li>Headline <input type="text" name="headline" value="New headline" maxlength="50" /></li> 283 <li>Slug <input type="text" name="slug" value="new-headline" maxlength="50" /></li> 284 <li>Pub date <input type="text" name="pub_date" value="1988-01-04" /></li> 285 <li>Writer <select name="writer"> 286 286 <option value="">---------</option> 287 287 <option value="1" selected="selected">Mike Royko</option> 288 288 <option value="2">Bob Woodward</option> 289 289 </select></li> 290 <li>Article :<textarea rows="10" cols="40" name="article">Hello.</textarea></li>291 <li>Status :<select name="status">290 <li>Article <textarea rows="10" cols="40" name="article">Hello.</textarea></li> 291 <li>Status <select name="status"> 292 292 <option value="" selected="selected">---------</option> 293 293 <option value="1">Draft</option> 294 294 <option value="2">Pending</option> 295 295 <option value="3">Live</option> 296 296 </select></li> 297 <li>Categories :<select multiple="multiple" name="categories">297 <li>Categories <select multiple="multiple" name="categories"> 298 298 <option value="1" selected="selected">Entertainment</option> 299 299 <option value="2">It's a test</option> 300 300 <option value="3">Third test</option> … … 387 387 >>> ArticleForm = form_for_model(Article) 388 388 >>> f = ArticleForm(auto_id=False) 389 389 >>> print f.as_ul() 390 <li>Headline :<input type="text" name="headline" maxlength="50" /></li>391 <li>Slug :<input type="text" name="slug" maxlength="50" /></li>392 <li>Pub date :<input type="text" name="pub_date" /></li>393 <li>Writer :<select name="writer">390 <li>Headline <input type="text" name="headline" maxlength="50" /></li> 391 <li>Slug <input type="text" name="slug" maxlength="50" /></li> 392 <li>Pub date <input type="text" name="pub_date" /></li> 393 <li>Writer <select name="writer"> 394 394 <option value="" selected="selected">---------</option> 395 395 <option value="1">Mike Royko</option> 396 396 <option value="2">Bob Woodward</option> 397 397 </select></li> 398 <li>Article :<textarea rows="10" cols="40" name="article"></textarea></li>399 <li>Status :<select name="status">398 <li>Article <textarea rows="10" cols="40" name="article"></textarea></li> 399 <li>Status <select name="status"> 400 400 <option value="" selected="selected">---------</option> 401 401 <option value="1">Draft</option> 402 402 <option value="2">Pending</option> 403 403 <option value="3">Live</option> 404 404 </select></li> 405 <li>Categories :<select multiple="multiple" name="categories">405 <li>Categories <select multiple="multiple" name="categories"> 406 406 <option value="1">Entertainment</option> 407 407 <option value="2">It's a test</option> 408 408 <option value="3">Third</option> … … 412 412 >>> Writer.objects.create(name='Carl Bernstein') 413 413 <Writer: Carl Bernstein> 414 414 >>> print f.as_ul() 415 <li>Headline :<input type="text" name="headline" maxlength="50" /></li>416 <li>Slug :<input type="text" name="slug" maxlength="50" /></li>417 <li>Pub date :<input type="text" name="pub_date" /></li>418 <li>Writer :<select name="writer">415 <li>Headline <input type="text" name="headline" maxlength="50" /></li> 416 <li>Slug <input type="text" name="slug" maxlength="50" /></li> 417 <li>Pub date <input type="text" name="pub_date" /></li> 418 <li>Writer <select name="writer"> 419 419 <option value="" selected="selected">---------</option> 420 420 <option value="1">Mike Royko</option> 421 421 <option value="2">Bob Woodward</option> 422 422 <option value="3">Carl Bernstein</option> 423 423 </select></li> 424 <li>Article :<textarea rows="10" cols="40" name="article"></textarea></li>425 <li>Status :<select name="status">424 <li>Article <textarea rows="10" cols="40" name="article"></textarea></li> 425 <li>Status <select name="status"> 426 426 <option value="" selected="selected">---------</option> 427 427 <option value="1">Draft</option> 428 428 <option value="2">Pending</option> 429 429 <option value="3">Live</option> 430 430 </select></li> 431 <li>Categories :<select multiple="multiple" name="categories">431 <li>Categories <select multiple="multiple" name="categories"> 432 432 <option value="1">Entertainment</option> 433 433 <option value="2">It's a test</option> 434 434 <option value="3">Third</option> -
tests/regressiontests/forms/tests.py
old new 347 347 ... somechoice = ChoiceField(choices=chain((('', '-'*9),), [(thing['id'], thing['name']) for thing in things])) 348 348 >>> f = SomeForm() 349 349 >>> f.as_table() 350 u'<tr><th><label for="id_somechoice">Somechoice :</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>'350 u'<tr><th><label for="id_somechoice">Somechoice</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>' 351 351 >>> f.as_table() 352 u'<tr><th><label for="id_somechoice">Somechoice :</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>'352 u'<tr><th><label for="id_somechoice">Somechoice</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="" selected="selected">---------</option>\n<option value="1">And Boom</option>\n<option value="2">One More Thing!</option>\n</select></td></tr>' 353 353 >>> f = SomeForm({'somechoice': 2}) 354 354 >>> f.as_table() 355 u'<tr><th><label for="id_somechoice">Somechoice :</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="">---------</option>\n<option value="1">And Boom</option>\n<option value="2" selected="selected">One More Thing!</option>\n</select></td></tr>'355 u'<tr><th><label for="id_somechoice">Somechoice</label></th><td><select name="somechoice" id="id_somechoice">\n<option value="">---------</option>\n<option value="1">And Boom</option>\n<option value="2" selected="selected">One More Thing!</option>\n</select></td></tr>' 356 356 357 357 You can also pass 'choices' to the constructor: 358 358 >>> w = Select(choices=[(1, 1), (2, 2), (3, 3)]) … … 2048 2048 Last name Lennon 2049 2049 Birthday 1940-10-9 2050 2050 >>> print p 2051 <tr><th><label for="id_first_name">First name :</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>2052 <tr><th><label for="id_last_name">Last name :</label></th><td><input type="text" name="last_name" value="Lennon" id="id_last_name" /></td></tr>2053 <tr><th><label for="id_birthday">Birthday :</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>2051 <tr><th><label for="id_first_name">First name</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr> 2052 <tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" value="Lennon" id="id_last_name" /></td></tr> 2053 <tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr> 2054 2054 2055 2055 Empty dictionaries are valid, too. 2056 2056 >>> p = Person({}) … … 2065 2065 ... 2066 2066 AttributeError: 'Person' object has no attribute 'cleaned_data' 2067 2067 >>> print p 2068 <tr><th><label for="id_first_name">First name :</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr>2069 <tr><th><label for="id_last_name">Last name :</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr>2070 <tr><th><label for="id_birthday">Birthday :</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr>2068 <tr><th><label for="id_first_name">First name</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr> 2069 <tr><th><label for="id_last_name">Last name</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr> 2070 <tr><th><label for="id_birthday">Birthday</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr> 2071 2071 >>> print p.as_table() 2072 <tr><th><label for="id_first_name">First name :</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr>2073 <tr><th><label for="id_last_name">Last name :</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr>2074 <tr><th><label for="id_birthday">Birthday :</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr>2072 <tr><th><label for="id_first_name">First name</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr> 2073 <tr><th><label for="id_last_name">Last name</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr> 2074 <tr><th><label for="id_birthday">Birthday</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="birthday" id="id_birthday" /></td></tr> 2075 2075 >>> print p.as_ul() 2076 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_first_name">First name :</label> <input type="text" name="first_name" id="id_first_name" /></li>2077 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_last_name">Last name :</label> <input type="text" name="last_name" id="id_last_name" /></li>2078 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_birthday">Birthday :</label> <input type="text" name="birthday" id="id_birthday" /></li>2076 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></li> 2077 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></li> 2078 <li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /></li> 2079 2079 >>> print p.as_p() 2080 2080 <ul class="errorlist"><li>This field is required.</li></ul> 2081 <p><label for="id_first_name">First name :</label> <input type="text" name="first_name" id="id_first_name" /></p>2081 <p><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></p> 2082 2082 <ul class="errorlist"><li>This field is required.</li></ul> 2083 <p><label for="id_last_name">Last name :</label> <input type="text" name="last_name" id="id_last_name" /></p>2083 <p><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></p> 2084 2084 <ul class="errorlist"><li>This field is required.</li></ul> 2085 <p><label for="id_birthday">Birthday :</label> <input type="text" name="birthday" id="id_birthday" /></p>2085 <p><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /></p> 2086 2086 2087 2087 If you don't pass any values to the Form's __init__(), or if you pass None, 2088 2088 the Form will be considered unbound and won't do any validation. Form.errors … … 2099 2099 ... 2100 2100 AttributeError: 'Person' object has no attribute 'cleaned_data' 2101 2101 >>> print p 2102 <tr><th><label for="id_first_name">First name :</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>2103 <tr><th><label for="id_last_name">Last name :</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>2104 <tr><th><label for="id_birthday">Birthday :</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr>2102 <tr><th><label for="id_first_name">First name</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 2103 <tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 2104 <tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr> 2105 2105 >>> print p.as_table() 2106 <tr><th><label for="id_first_name">First name :</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>2107 <tr><th><label for="id_last_name">Last name :</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>2108 <tr><th><label for="id_birthday">Birthday :</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr>2106 <tr><th><label for="id_first_name">First name</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 2107 <tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 2108 <tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" id="id_birthday" /></td></tr> 2109 2109 >>> print p.as_ul() 2110 <li><label for="id_first_name">First name :</label> <input type="text" name="first_name" id="id_first_name" /></li>2111 <li><label for="id_last_name">Last name :</label> <input type="text" name="last_name" id="id_last_name" /></li>2112 <li><label for="id_birthday">Birthday :</label> <input type="text" name="birthday" id="id_birthday" /></li>2110 <li><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></li> 2111 <li><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></li> 2112 <li><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /></li> 2113 2113 >>> print p.as_p() 2114 <p><label for="id_first_name">First name :</label> <input type="text" name="first_name" id="id_first_name" /></p>2115 <p><label for="id_last_name">Last name :</label> <input type="text" name="last_name" id="id_last_name" /></p>2116 <p><label for="id_birthday">Birthday :</label> <input type="text" name="birthday" id="id_birthday" /></p>2114 <p><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></p> 2115 <p><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></p> 2116 <p><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /></p> 2117 2117 2118 2118 Unicode values are handled properly. 2119 2119 >>> p = Person({'first_name': u'John', 'last_name': u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111', 'birthday': '1940-10-9'}) 2120 2120 >>> p.as_table() 2121 u'<tr><th><label for="id_first_name">First name :</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>\n<tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></td></tr>\n<tr><th><label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>'2121 u'<tr><th><label for="id_first_name">First name</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>\n<tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></td></tr>\n<tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></td></tr>' 2122 2122 >>> p.as_ul() 2123 u'<li><label for="id_first_name">First name :</label> <input type="text" name="first_name" value="John" id="id_first_name" /></li>\n<li><label for="id_last_name">Last name:</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></li>\n<li><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></li>'2123 u'<li><label for="id_first_name">First name</label> <input type="text" name="first_name" value="John" id="id_first_name" /></li>\n<li><label for="id_last_name">Last name</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></li>\n<li><label for="id_birthday">Birthday</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></li>' 2124 2124 >>> p.as_p() 2125 u'<p><label for="id_first_name">First name :</label> <input type="text" name="first_name" value="John" id="id_first_name" /></p>\n<p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></p>\n<p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></p>'2125 u'<p><label for="id_first_name">First name</label> <input type="text" name="first_name" value="John" id="id_first_name" /></p>\n<p><label for="id_last_name">Last name</label> <input type="text" name="last_name" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" id="id_last_name" /></p>\n<p><label for="id_birthday">Birthday</label> <input type="text" name="birthday" value="1940-10-9" id="id_birthday" /></p>' 2126 2126 2127 2127 >>> p = Person({'last_name': u'Lennon'}) 2128 2128 >>> p.errors … … 2200 2200 the human-readable labels for a field. 2201 2201 >>> p = Person(auto_id='%s_id') 2202 2202 >>> print p.as_table() 2203 <tr><th><label for="first_name_id">First name :</label></th><td><input type="text" name="first_name" id="first_name_id" /></td></tr>2204 <tr><th><label for="last_name_id">Last name :</label></th><td><input type="text" name="last_name" id="last_name_id" /></td></tr>2205 <tr><th><label for="birthday_id">Birthday :</label></th><td><input type="text" name="birthday" id="birthday_id" /></td></tr>2203 <tr><th><label for="first_name_id">First name</label></th><td><input type="text" name="first_name" id="first_name_id" /></td></tr> 2204 <tr><th><label for="last_name_id">Last name</label></th><td><input type="text" name="last_name" id="last_name_id" /></td></tr> 2205 <tr><th><label for="birthday_id">Birthday</label></th><td><input type="text" name="birthday" id="birthday_id" /></td></tr> 2206 2206 >>> print p.as_ul() 2207 <li><label for="first_name_id">First name :</label> <input type="text" name="first_name" id="first_name_id" /></li>2208 <li><label for="last_name_id">Last name :</label> <input type="text" name="last_name" id="last_name_id" /></li>2209 <li><label for="birthday_id">Birthday :</label> <input type="text" name="birthday" id="birthday_id" /></li>2207 <li><label for="first_name_id">First name</label> <input type="text" name="first_name" id="first_name_id" /></li> 2208 <li><label for="last_name_id">Last name</label> <input type="text" name="last_name" id="last_name_id" /></li> 2209 <li><label for="birthday_id">Birthday</label> <input type="text" name="birthday" id="birthday_id" /></li> 2210 2210 >>> print p.as_p() 2211 <p><label for="first_name_id">First name :</label> <input type="text" name="first_name" id="first_name_id" /></p>2212 <p><label for="last_name_id">Last name :</label> <input type="text" name="last_name" id="last_name_id" /></p>2213 <p><label for="birthday_id">Birthday :</label> <input type="text" name="birthday" id="birthday_id" /></p>2211 <p><label for="first_name_id">First name</label> <input type="text" name="first_name" id="first_name_id" /></p> 2212 <p><label for="last_name_id">Last name</label> <input type="text" name="last_name" id="last_name_id" /></p> 2213 <p><label for="birthday_id">Birthday</label> <input type="text" name="birthday" id="birthday_id" /></p> 2214 2214 2215 2215 If auto_id is any True value whose str() does not contain '%s', the "id" 2216 2216 attribute will be the name of the field. 2217 2217 >>> p = Person(auto_id=True) 2218 2218 >>> print p.as_ul() 2219 <li><label for="first_name">First name :</label> <input type="text" name="first_name" id="first_name" /></li>2220 <li><label for="last_name">Last name :</label> <input type="text" name="last_name" id="last_name" /></li>2221 <li><label for="birthday">Birthday :</label> <input type="text" name="birthday" id="birthday" /></li>2219 <li><label for="first_name">First name</label> <input type="text" name="first_name" id="first_name" /></li> 2220 <li><label for="last_name">Last name</label> <input type="text" name="last_name" id="last_name" /></li> 2221 <li><label for="birthday">Birthday</label> <input type="text" name="birthday" id="birthday" /></li> 2222 2222 2223 2223 If auto_id is any False value, an "id" attribute won't be output unless it 2224 2224 was manually entered. 2225 2225 >>> p = Person(auto_id=False) 2226 2226 >>> print p.as_ul() 2227 <li>First name :<input type="text" name="first_name" /></li>2228 <li>Last name :<input type="text" name="last_name" /></li>2229 <li>Birthday :<input type="text" name="birthday" /></li>2227 <li>First name <input type="text" name="first_name" /></li> 2228 <li>Last name <input type="text" name="last_name" /></li> 2229 <li>Birthday <input type="text" name="birthday" /></li> 2230 2230 2231 2231 In this example, auto_id is False, but the "id" attribute for the "first_name" 2232 2232 field is given. Also note that field gets a <label>, while the others don't. … … 2236 2236 ... birthday = DateField() 2237 2237 >>> p = PersonNew(auto_id=False) 2238 2238 >>> print p.as_ul() 2239 <li><label for="first_name_id">First name :</label> <input type="text" id="first_name_id" name="first_name" /></li>2240 <li>Last name :<input type="text" name="last_name" /></li>2241 <li>Birthday :<input type="text" name="birthday" /></li>2239 <li><label for="first_name_id">First name</label> <input type="text" id="first_name_id" name="first_name" /></li> 2240 <li>Last name <input type="text" name="last_name" /></li> 2241 <li>Birthday <input type="text" name="birthday" /></li> 2242 2242 2243 2243 If the "id" attribute is specified in the Form and auto_id is True, the "id" 2244 2244 attribute in the Form gets precedence. 2245 2245 >>> p = PersonNew(auto_id=True) 2246 2246 >>> print p.as_ul() 2247 <li><label for="first_name_id">First name :</label> <input type="text" id="first_name_id" name="first_name" /></li>2248 <li><label for="last_name">Last name :</label> <input type="text" name="last_name" id="last_name" /></li>2249 <li><label for="birthday">Birthday :</label> <input type="text" name="birthday" id="birthday" /></li>2247 <li><label for="first_name_id">First name</label> <input type="text" id="first_name_id" name="first_name" /></li> 2248 <li><label for="last_name">Last name</label> <input type="text" name="last_name" id="last_name" /></li> 2249 <li><label for="birthday">Birthday</label> <input type="text" name="birthday" id="birthday" /></li> 2250 2250 2251 2251 >>> class SignupForm(Form): 2252 2252 ... email = EmailField() … … 2394 2394 <li><label><input type="radio" name="language" value="J" /> Java</label></li> 2395 2395 </ul> 2396 2396 >>> print f 2397 <tr><th>Name :</th><td><input type="text" name="name" /></td></tr>2398 <tr><th>Language :</th><td><ul>2397 <tr><th>Name</th><td><input type="text" name="name" /></td></tr> 2398 <tr><th>Language</th><td><ul> 2399 2399 <li><label><input type="radio" name="language" value="P" /> Python</label></li> 2400 2400 <li><label><input type="radio" name="language" value="J" /> Java</label></li> 2401 2401 </ul></td></tr> 2402 2402 >>> print f.as_ul() 2403 <li>Name :<input type="text" name="name" /></li>2404 <li>Language :<ul>2403 <li>Name <input type="text" name="name" /></li> 2404 <li>Language <ul> 2405 2405 <li><label><input type="radio" name="language" value="P" /> Python</label></li> 2406 2406 <li><label><input type="radio" name="language" value="J" /> Java</label></li> 2407 2407 </ul></li> … … 2420 2420 either as_table() or as_ul(), the label for the RadioSelect will point to the 2421 2421 ID of the *first* radio button. 2422 2422 >>> print f 2423 <tr><th><label for="id_name">Name :</label></th><td><input type="text" name="name" id="id_name" /></td></tr>2424 <tr><th><label for="id_language_0">Language :</label></th><td><ul>2423 <tr><th><label for="id_name">Name</label></th><td><input type="text" name="name" id="id_name" /></td></tr> 2424 <tr><th><label for="id_language_0">Language</label></th><td><ul> 2425 2425 <li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li> 2426 2426 <li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li> 2427 2427 </ul></td></tr> 2428 2428 >>> print f.as_ul() 2429 <li><label for="id_name">Name :</label> <input type="text" name="name" id="id_name" /></li>2430 <li><label for="id_language_0">Language :</label> <ul>2429 <li><label for="id_name">Name</label> <input type="text" name="name" id="id_name" /></li> 2430 <li><label for="id_language_0">Language</label> <ul> 2431 2431 <li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li> 2432 2432 <li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li> 2433 2433 </ul></li> 2434 2434 >>> print f.as_p() 2435 <p><label for="id_name">Name :</label> <input type="text" name="name" id="id_name" /></p>2436 <p><label for="id_language_0">Language :</label> <ul>2435 <p><label for="id_name">Name</label> <input type="text" name="name" id="id_name" /></p> 2436 <p><label for="id_language_0">Language</label> <ul> 2437 2437 <li><label><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li> 2438 2438 <li><label><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li> 2439 2439 </ul></p> … … 2531 2531 ... composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')], widget=MultipleHiddenInput) 2532 2532 >>> f = SongFormHidden(MultiValueDict(dict(name=['Yesterday'], composers=['J', 'P'])), auto_id=False) 2533 2533 >>> print f.as_ul() 2534 <li>Name :<input type="text" name="name" value="Yesterday" /><input type="hidden" name="composers" value="J" />2534 <li>Name <input type="text" name="name" value="Yesterday" /><input type="hidden" name="composers" value="J" /> 2535 2535 <input type="hidden" name="composers" value="P" /></li> 2536 2536 2537 2537 When using CheckboxSelectMultiple, the framework expects a list of input and … … 2558 2558 2559 2559 >>> f = EscapingForm({'special_name': "Nothing to escape"}, auto_id=False) 2560 2560 >>> print f 2561 <tr><th>Special name :</th><td><ul class="errorlist"><li>Something's wrong with 'Nothing to escape'</li></ul><input type="text" name="special_name" value="Nothing to escape" /></td></tr>2561 <tr><th>Special name</th><td><ul class="errorlist"><li>Something's wrong with 'Nothing to escape'</li></ul><input type="text" name="special_name" value="Nothing to escape" /></td></tr> 2562 2562 >>> f = EscapingForm({'special_name': "Should escape < & > and <script>alert('xss')</script>"}, auto_id=False) 2563 2563 >>> print f 2564 <tr><th>Special name :</th><td><ul class="errorlist"><li>Something's wrong with 'Should escape < & > and <script>alert('xss')</script>'</li></ul><input type="text" name="special_name" value="Should escape < & > and <script>alert('xss')</script>" /></td></tr>2564 <tr><th>Special name</th><td><ul class="errorlist"><li>Something's wrong with 'Should escape < & > and <script>alert('xss')</script>'</li></ul><input type="text" name="special_name" value="Should escape < & > and <script>alert('xss')</script>" /></td></tr> 2565 2565 2566 2566 # Validating multiple fields in relation to another ########################### 2567 2567 … … 2615 2615 {} 2616 2616 >>> f = UserRegistration({}, auto_id=False) 2617 2617 >>> print f.as_table() 2618 <tr><th>Username :</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="username" maxlength="10" /></td></tr>2619 <tr><th>Password1 :</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password1" /></td></tr>2620 <tr><th>Password2 :</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password2" /></td></tr>2618 <tr><th>Username</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="username" maxlength="10" /></td></tr> 2619 <tr><th>Password1</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password1" /></td></tr> 2620 <tr><th>Password2</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="password" name="password2" /></td></tr> 2621 2621 >>> f.errors 2622 2622 {'username': [u'This field is required.'], 'password1': [u'This field is required.'], 'password2': [u'This field is required.']} 2623 2623 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'bar'}, auto_id=False) … … 2625 2625 {'__all__': [u'Please make sure your passwords match.']} 2626 2626 >>> print f.as_table() 2627 2627 <tr><td colspan="2"><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></td></tr> 2628 <tr><th>Username :</th><td><input type="text" name="username" value="adrian" maxlength="10" /></td></tr>2629 <tr><th>Password1 :</th><td><input type="password" name="password1" value="foo" /></td></tr>2630 <tr><th>Password2 :</th><td><input type="password" name="password2" value="bar" /></td></tr>2628 <tr><th>Username</th><td><input type="text" name="username" value="adrian" maxlength="10" /></td></tr> 2629 <tr><th>Password1</th><td><input type="password" name="password1" value="foo" /></td></tr> 2630 <tr><th>Password2</th><td><input type="password" name="password2" value="bar" /></td></tr> 2631 2631 >>> print f.as_ul() 2632 2632 <li><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></li> 2633 <li>Username :<input type="text" name="username" value="adrian" maxlength="10" /></li>2634 <li>Password1 :<input type="password" name="password1" value="foo" /></li>2635 <li>Password2 :<input type="password" name="password2" value="bar" /></li>2633 <li>Username <input type="text" name="username" value="adrian" maxlength="10" /></li> 2634 <li>Password1 <input type="password" name="password1" value="foo" /></li> 2635 <li>Password2 <input type="password" name="password2" value="bar" /></li> 2636 2636 >>> f = UserRegistration({'username': 'adrian', 'password1': 'foo', 'password2': 'foo'}, auto_id=False) 2637 2637 >>> f.errors 2638 2638 {} … … 2652 2652 ... self.fields['birthday'] = DateField() 2653 2653 >>> p = Person(auto_id=False) 2654 2654 >>> print p 2655 <tr><th>First name :</th><td><input type="text" name="first_name" /></td></tr>2656 <tr><th>Last name :</th><td><input type="text" name="last_name" /></td></tr>2657 <tr><th>Birthday :</th><td><input type="text" name="birthday" /></td></tr>2655 <tr><th>First name</th><td><input type="text" name="first_name" /></td></tr> 2656 <tr><th>Last name</th><td><input type="text" name="last_name" /></td></tr> 2657 <tr><th>Birthday</th><td><input type="text" name="birthday" /></td></tr> 2658 2658 2659 2659 Instances of a dynamic Form do not persist fields from one Form instance to 2660 2660 the next. … … 2666 2666 >>> field_list = [('field1', CharField()), ('field2', CharField())] 2667 2667 >>> my_form = MyForm(field_list=field_list) 2668 2668 >>> print my_form 2669 <tr><th>Field1 :</th><td><input type="text" name="field1" /></td></tr>2670 <tr><th>Field2 :</th><td><input type="text" name="field2" /></td></tr>2669 <tr><th>Field1</th><td><input type="text" name="field1" /></td></tr> 2670 <tr><th>Field2</th><td><input type="text" name="field2" /></td></tr> 2671 2671 >>> field_list = [('field3', CharField()), ('field4', CharField())] 2672 2672 >>> my_form = MyForm(field_list=field_list) 2673 2673 >>> print my_form 2674 <tr><th>Field3 :</th><td><input type="text" name="field3" /></td></tr>2675 <tr><th>Field4 :</th><td><input type="text" name="field4" /></td></tr>2674 <tr><th>Field3</th><td><input type="text" name="field3" /></td></tr> 2675 <tr><th>Field4</th><td><input type="text" name="field4" /></td></tr> 2676 2676 2677 2677 >>> class MyForm(Form): 2678 2678 ... default_field_1 = CharField() … … 2684 2684 >>> field_list = [('field1', CharField()), ('field2', CharField())] 2685 2685 >>> my_form = MyForm(field_list=field_list) 2686 2686 >>> print my_form 2687 <tr><th>Default field 1 :</th><td><input type="text" name="default_field_1" /></td></tr>2688 <tr><th>Default field 2 :</th><td><input type="text" name="default_field_2" /></td></tr>2689 <tr><th>Field1 :</th><td><input type="text" name="field1" /></td></tr>2690 <tr><th>Field2 :</th><td><input type="text" name="field2" /></td></tr>2687 <tr><th>Default field 1</th><td><input type="text" name="default_field_1" /></td></tr> 2688 <tr><th>Default field 2</th><td><input type="text" name="default_field_2" /></td></tr> 2689 <tr><th>Field1</th><td><input type="text" name="field1" /></td></tr> 2690 <tr><th>Field2</th><td><input type="text" name="field2" /></td></tr> 2691 2691 >>> field_list = [('field3', CharField()), ('field4', CharField())] 2692 2692 >>> my_form = MyForm(field_list=field_list) 2693 2693 >>> print my_form 2694 <tr><th>Default field 1 :</th><td><input type="text" name="default_field_1" /></td></tr>2695 <tr><th>Default field 2 :</th><td><input type="text" name="default_field_2" /></td></tr>2696 <tr><th>Field3 :</th><td><input type="text" name="field3" /></td></tr>2697 <tr><th>Field4 :</th><td><input type="text" name="field4" /></td></tr>2694 <tr><th>Default field 1</th><td><input type="text" name="default_field_1" /></td></tr> 2695 <tr><th>Default field 2</th><td><input type="text" name="default_field_2" /></td></tr> 2696 <tr><th>Field3</th><td><input type="text" name="field3" /></td></tr> 2697 <tr><th>Field4</th><td><input type="text" name="field4" /></td></tr> 2698 2698 2699 2699 Similarly, changes to field attributes do not persist from one Form instance 2700 2700 to the next. … … 2752 2752 ... birthday = DateField() 2753 2753 >>> p = Person(auto_id=False) 2754 2754 >>> print p 2755 <tr><th>First name :</th><td><input type="text" name="first_name" /></td></tr>2756 <tr><th>Last name :</th><td><input type="text" name="last_name" /></td></tr>2757 <tr><th>Birthday :</th><td><input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></td></tr>2755 <tr><th>First name</th><td><input type="text" name="first_name" /></td></tr> 2756 <tr><th>Last name</th><td><input type="text" name="last_name" /></td></tr> 2757 <tr><th>Birthday</th><td><input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></td></tr> 2758 2758 >>> print p.as_ul() 2759 <li>First name :<input type="text" name="first_name" /></li>2760 <li>Last name :<input type="text" name="last_name" /></li>2761 <li>Birthday :<input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></li>2759 <li>First name <input type="text" name="first_name" /></li> 2760 <li>Last name <input type="text" name="last_name" /></li> 2761 <li>Birthday <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></li> 2762 2762 >>> print p.as_p() 2763 <p>First name :<input type="text" name="first_name" /></p>2764 <p>Last name :<input type="text" name="last_name" /></p>2765 <p>Birthday :<input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></p>2763 <p>First name <input type="text" name="first_name" /></p> 2764 <p>Last name <input type="text" name="last_name" /></p> 2765 <p>Birthday <input type="text" name="birthday" /><input type="hidden" name="hidden_text" /></p> 2766 2766 2767 2767 With auto_id set, a HiddenInput still gets an ID, but it doesn't get a label. 2768 2768 >>> p = Person(auto_id='id_%s') 2769 2769 >>> print p 2770 <tr><th><label for="id_first_name">First name :</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>2771 <tr><th><label for="id_last_name">Last name :</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>2772 <tr><th><label for="id_birthday">Birthday :</label></th><td><input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></td></tr>2770 <tr><th><label for="id_first_name">First name</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 2771 <tr><th><label for="id_last_name">Last name</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr> 2772 <tr><th><label for="id_birthday">Birthday</label></th><td><input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></td></tr> 2773 2773 >>> print p.as_ul() 2774 <li><label for="id_first_name">First name :</label> <input type="text" name="first_name" id="id_first_name" /></li>2775 <li><label for="id_last_name">Last name :</label> <input type="text" name="last_name" id="id_last_name" /></li>2776 <li><label for="id_birthday">Birthday :</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></li>2774 <li><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></li> 2775 <li><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></li> 2776 <li><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></li> 2777 2777 >>> print p.as_p() 2778 <p><label for="id_first_name">First name :</label> <input type="text" name="first_name" id="id_first_name" /></p>2779 <p><label for="id_last_name">Last name :</label> <input type="text" name="last_name" id="id_last_name" /></p>2780 <p><label for="id_birthday">Birthday :</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></p>2778 <p><label for="id_first_name">First name</label> <input type="text" name="first_name" id="id_first_name" /></p> 2779 <p><label for="id_last_name">Last name</label> <input type="text" name="last_name" id="id_last_name" /></p> 2780 <p><label for="id_birthday">Birthday</label> <input type="text" name="birthday" id="id_birthday" /><input type="hidden" name="hidden_text" id="id_hidden_text" /></p> 2781 2781 2782 2782 If a field with a HiddenInput has errors, the as_table() and as_ul() output 2783 2783 will include the error message(s) with the text "(Hidden field [fieldname]) " … … 2786 2786 >>> p = Person({'first_name': 'John', 'last_name': 'Lennon', 'birthday': '1940-10-9'}, auto_id=False) 2787 2787 >>> print p 2788 2788 <tr><td colspan="2"><ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul></td></tr> 2789 <tr><th>First name :</th><td><input type="text" name="first_name" value="John" /></td></tr>2790 <tr><th>Last name :</th><td><input type="text" name="last_name" value="Lennon" /></td></tr>2791 <tr><th>Birthday :</th><td><input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></td></tr>2789 <tr><th>First name</th><td><input type="text" name="first_name" value="John" /></td></tr> 2790 <tr><th>Last name</th><td><input type="text" name="last_name" value="Lennon" /></td></tr> 2791 <tr><th>Birthday</th><td><input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></td></tr> 2792 27
