diff options
| author | David Smith <smithdc@gmail.com> | 2020-02-13 22:12:46 +0000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-03-24 20:05:18 +0100 |
| commit | 27746ab28ac88fc213456e63302b408312d95122 (patch) | |
| tree | a1a1946d190833610bce0c5e2dd1b721972bbb0e /docs | |
| parent | 8fe2447a01232d9598bf4692d1face12fa074288 (diff) | |
Fixed #7664 -- Allowed customizing suffixes of MultiWidget.widgets' names.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/forms/widgets.txt | 22 | ||||
| -rw-r--r-- | docs/releases/3.1.txt | 3 |
2 files changed, 24 insertions, 1 deletions
diff --git a/docs/ref/forms/widgets.txt b/docs/ref/forms/widgets.txt index 02077f631f..5a54051cda 100644 --- a/docs/ref/forms/widgets.txt +++ b/docs/ref/forms/widgets.txt @@ -354,7 +354,27 @@ foundation for custom widgets. .. attribute:: MultiWidget.widgets - An iterable containing the widgets needed. + An iterable containing the widgets needed. For example:: + + >>> from django.forms import MultiWidget, TextInput + >>> widget = MultiWidget(widgets=[TextInput, TextInput]) + >>> widget.render('name', ['john', 'paul']) + '<input type="text" name="name_0" value="john"><input type="text" name="name_1" value="paul">' + + You may provide a dictionary in order to specify custom suffixes for + the ``name`` attribute on each subwidget. In this case, for each + ``(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:: + + >>> widget = MultiWidget(widgets={'': TextInput, 'last': TextInput}) + >>> widget.render('name', ['john', 'lennon']) + '<input type="text" name="name" value="john"><input type="text" name="name_last" value="paul">' + + .. versionchanged::3.1 + + Support for using a dictionary was added. And one required method: diff --git a/docs/releases/3.1.txt b/docs/releases/3.1.txt index 9961aebbab..630dd4bc35 100644 --- a/docs/releases/3.1.txt +++ b/docs/releases/3.1.txt @@ -270,6 +270,9 @@ Forms now uses ``DATE_INPUT_FORMATS`` in addition to ``DATETIME_INPUT_FORMATS`` when converting a field input to a ``datetime`` value. +* :attr:`.MultiWidget.widgets` now accepts a dictionary which allows + customizing subwidget ``name`` attributes. + Generic Views ~~~~~~~~~~~~~ |
