diff options
| author | David Smith <smithdc@gmail.com> | 2020-04-01 17:48:23 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-04-10 07:11:14 +0200 |
| commit | a350bfa6f44befff8779dbbdd72c9760bf5df959 (patch) | |
| tree | 1bc16fde273533e7566def447a26bfa888b782bc /docs | |
| parent | ab903fe304c347e669024ec482832df5f4fd869a (diff) | |
Fixed #13009 -- Added BoundField.widget_type property.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/forms/api.txt | 17 | ||||
| -rw-r--r-- | docs/releases/3.1.txt | 3 |
2 files changed, 20 insertions, 0 deletions
diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index 23fbab9aff..a084867011 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -972,6 +972,23 @@ Attributes of ``BoundField`` >>> print(f['message'].name) message +.. attribute:: BoundField.widget_type + + .. versionadded:: 3.1 + + Returns the lowercased class name of the wrapped field's widget, with any + trailing ``input`` or ``widget`` removed. This may be used when building + forms where the layout is dependent upon the widget type. For example:: + + {% for field in form %} + {% if field.widget_type == 'checkbox' %} + # render one way + {% else %} + # render another way + {% endif %} + {% endfor %} + + Methods of ``BoundField`` ------------------------- diff --git a/docs/releases/3.1.txt b/docs/releases/3.1.txt index 7df81329b4..85f4ca2d99 100644 --- a/docs/releases/3.1.txt +++ b/docs/releases/3.1.txt @@ -278,6 +278,9 @@ Forms * :attr:`.MultiWidget.widgets` now accepts a dictionary which allows customizing subwidget ``name`` attributes. +* The new :attr:`.BoundField.widget_type` property can be used to dynamically + adjust form rendering based upon the widget type. + Generic Views ~~~~~~~~~~~~~ |
