From 232b60a21b951bd16b8c95b34fcbcbf3ecd89fca Mon Sep 17 00:00:00 2001 From: David Smith Date: Sun, 12 Feb 2023 13:20:05 +0000 Subject: Refs #32339 -- Updated docs to reflect default
style form rendering in Django 5.0. Follow up to 98756c685ee173bbd43f21ed0553f808be835ce5. --- docs/ref/forms/fields.txt | 48 +++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) (limited to 'docs/ref/forms/fields.txt') diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt index edf32ecdab..a7095ba5dc 100644 --- a/docs/ref/forms/fields.txt +++ b/docs/ref/forms/fields.txt @@ -129,9 +129,9 @@ We've specified ``auto_id=False`` to simplify the output: ... comment = forms.CharField() >>> f = CommentForm(auto_id=False) >>> print(f) - Your name: - Your website: - Comment: +
Your name:
+
Your website:
+
Comment:
``label_suffix`` ---------------- @@ -148,10 +148,10 @@ The ``label_suffix`` argument lets you override the form's ... nationality = forms.CharField() ... captcha_answer = forms.IntegerField(label='2 + 2', label_suffix=' =') >>> f = ContactForm(label_suffix='?') - >>> print(f.as_p()) -

-

-

+ >>> print(f) +
+
+
``initial`` ----------- @@ -175,9 +175,9 @@ field is initialized to a particular value. For example: ... comment = forms.CharField() >>> f = CommentForm(auto_id=False) >>> print(f) - Name: - Url: - Comment: +
Name:
+
Url:
+
Comment:
You may be thinking, why not just pass a dictionary of the initial values as data when displaying the form? Well, if you do that, you'll trigger validation, @@ -192,9 +192,9 @@ and the HTML output will include any validation errors: >>> default_data = {'name': 'Your name', 'url': 'http://'} >>> f = CommentForm(default_data, auto_id=False) >>> print(f) - Name: - Url: - Comment: +
Name:
+
Url:
  • Enter a valid URL.
+
Comment:
  • This field is required.
This is why ``initial`` values are only displayed for unbound forms. For bound forms, the HTML output will use the bound data. @@ -225,7 +225,7 @@ Instead of a constant, you can also pass any callable: >>> class DateForm(forms.Form): ... day = forms.DateField(initial=datetime.date.today) >>> print(DateForm()) - Day: +
The callable will be evaluated only when the unbound form is displayed, not when it is defined. @@ -262,21 +262,11 @@ fields. We've specified ``auto_id=False`` to simplify the output: ... sender = forms.EmailField(help_text='A valid email address, please.') ... cc_myself = forms.BooleanField(required=False) >>> f = HelpTextContactForm(auto_id=False) - >>> print(f.as_table()) - Subject:
100 characters max. - Message: - Sender:
A valid email address, please. - Cc myself: - >>> print(f.as_ul())) -
  • Subject: 100 characters max.
  • -
  • Message:
  • -
  • Sender: A valid email address, please.
  • -
  • Cc myself:
  • - >>> print(f.as_p()) -

    Subject: 100 characters max.

    -

    Message:

    -

    Sender: A valid email address, please.

    -

    Cc myself:

    + >>> print(f) +
    Subject:
    100 characters max.
    +
    Message:
    +
    Sender:
    A valid email address, please.
    +
    Cc myself:
    ``error_messages`` ------------------ -- cgit v1.3