Fixed #7664 -- Allowed customizing suffixes of MultiWidget.widgets' names.

This commit is contained in:
David Smith 2020-02-13 22:12:46 +00:00 committed by Mariusz Felisiak
parent 8fe2447a01
commit 27746ab28a
4 changed files with 82 additions and 6 deletions

View file

@ -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: