1 | 622a623,637
|
---|
2 | > fieldset attribute for fields
|
---|
3 | > ~~~~~~~~~~~~~~~~~~~~
|
---|
4 | > New in the development version, you can add a fieldset attribute to fields that
|
---|
5 | > can be used by templates to group fields. In the form below, the template
|
---|
6 | > form.fields will have "fieldset" attributes you can group by, and also
|
---|
7 | > use for legends within html fields.
|
---|
8 | >
|
---|
9 | > class ContactForm(forms.Form):
|
---|
10 | > subject = forms.CharField(max_length=100, fieldset="Required")
|
---|
11 | > message = forms.CharField(fieldset="Required")
|
---|
12 | > sender = forms.EmailField(fieldset="Required")
|
---|
13 | > cc_myself = forms.BooleanField(required=False)
|
---|
14 | >
|
---|
15 | >
|
---|
16 | >
|
---|
17 | 723a739,783
|
---|
18 | > New in the development version, you can also use passed fieldset attributes to
|
---|
19 | > layout the form fields in html fieldsets, using the attribute value as the legend.
|
---|
20 | >
|
---|
21 | > <form method="post" action="">
|
---|
22 | > <dl>
|
---|
23 | > {% regroup form by fieldset as fields_list %}
|
---|
24 | > {% for fields in fields_list %}
|
---|
25 | > <fieldset>
|
---|
26 | > <legend>{{ fields.grouper|upper }}</legend>
|
---|
27 | > {% for field in fields.list %}
|
---|
28 | > <dt>{{ field.label_tag }}</dt>
|
---|
29 | > <dd>{{ field }}</dd>
|
---|
30 | > {% if field.help_text %}<dd>{{ field.help_text }}</dd>{% endif %}
|
---|
31 | > {% if field.errors %}<dd class="myerrors">{{ field.errors }}</dd>{% endif %}
|
---|
32 | > {% endfor %}
|
---|
33 | > {% endfor %}
|
---|
34 | > </dl>
|
---|
35 | > <input type="submit" />
|
---|
36 | > </form>
|
---|
37 | >
|
---|
38 | >
|
---|
39 | > This will output the following HTML.
|
---|
40 | >
|
---|
41 | > <fieldset>
|
---|
42 | > <legend>REQUIRED</legend>
|
---|
43 | >
|
---|
44 | > <label for="id_subject">Subject</label> <input id="id_subject" type="text" name="subject" maxlength="100" />
|
---|
45 | >
|
---|
46 | > <label for="id_message">Message</label> <input type="text" name="message" id="id_message" />
|
---|
47 | >
|
---|
48 | > <label for="id_sender">Sender</label> <input type="text" name="sender" id="id_sender" />
|
---|
49 | >
|
---|
50 | >
|
---|
51 | > </fieldset>
|
---|
52 | >
|
---|
53 | > <fieldset>
|
---|
54 | > <legend></legend>
|
---|
55 | >
|
---|
56 | > <label for="id_cc_myself">Cc myself</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" />
|
---|
57 | >
|
---|
58 | > </fieldset>
|
---|
59 | >
|
---|
60 | > <input type="submit" value="Submit" />
|
---|
61 | >
|
---|
62 | >
|
---|
63 | 2156c2216
|
---|
64 | < a formset out of an ``ArticleForm`` you would do::
|
---|
65 | ---
|
---|
66 | > a formset of out of an ``ArticleForm`` you would do::
|
---|