summaryrefslogtreecommitdiff
path: root/docs/ref/forms/widgets.txt
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2023-02-09 16:48:46 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-02-10 21:12:06 +0100
commitb784768eef75afb32f6d2ce7166551a528bce0ec (patch)
treea375a57a50f1766538ea8a62ec49bda352d7f2b9 /docs/ref/forms/widgets.txt
parent4a89aa25c91e520c247aee428782274dcf10ffd0 (diff)
[4.2.x] Refs #34140 -- Applied rst code-block to non-Python examples.
Thanks to J.V. Zammit, Paolo Melchiorre, and Mariusz Felisiak for reviews. Backport of 534ac4829764f317cf2fbc4a18354fcc998c1425 from main.
Diffstat (limited to 'docs/ref/forms/widgets.txt')
-rw-r--r--docs/ref/forms/widgets.txt20
1 files changed, 15 insertions, 5 deletions
diff --git a/docs/ref/forms/widgets.txt b/docs/ref/forms/widgets.txt
index 40c030669c..729bbc718e 100644
--- a/docs/ref/forms/widgets.txt
+++ b/docs/ref/forms/widgets.txt
@@ -86,7 +86,9 @@ buttons.
:class:`Select` widgets are used by default on :class:`ChoiceField` fields. The
choices displayed on the widget are inherited from the :class:`ChoiceField` and
changing :attr:`ChoiceField.choices` will update :attr:`Select.choices`. For
-example::
+example:
+
+.. code-block:: pycon
>>> from django import forms
>>> CHOICES = [('1', 'First'), ('2', 'Second')]
@@ -137,7 +139,9 @@ For example, take the following form::
This form will include three default :class:`TextInput` widgets, with default
rendering -- no CSS class, no extra attributes. This means that the input boxes
-provided for each widget will be rendered exactly the same::
+provided for each widget will be rendered exactly the same:
+
+.. code-block:: pycon
>>> f = CommentForm(auto_id=False)
>>> f.as_table()
@@ -232,7 +236,9 @@ foundation for custom widgets.
'<input title="Your name" type="text" name="name" value="A name" size="10">'
If you assign a value of ``True`` or ``False`` to an attribute,
- it will be rendered as an HTML5 boolean attribute::
+ it will be rendered as an HTML5 boolean attribute:
+
+ .. code-block:: pycon
>>> name = forms.TextInput(attrs={'required': True})
>>> name.render('name', 'A name')
@@ -363,7 +369,9 @@ foundation for custom widgets.
.. attribute:: MultiWidget.widgets
- An iterable containing the widgets needed. For example::
+ An iterable containing the widgets needed. For example:
+
+ .. code-block:: pycon
>>> from django.forms import MultiWidget, TextInput
>>> widget = MultiWidget(widgets=[TextInput, TextInput])
@@ -375,7 +383,9 @@ foundation for custom widgets.
``(key, widget)`` pair, the key will be appended to the ``name`` of the
widget in order to generate the attribute value. You may provide the
empty string (``''``) for a single key, in order to suppress the suffix
- for one widget. For example::
+ for one widget. For example:
+
+ .. code-block:: pycon
>>> widget = MultiWidget(widgets={'': TextInput, 'last': TextInput})
>>> widget.render('name', ['john', 'paul'])