Skip to content

Commit 40869d4

Browse files
committed
Update README
1 parent 9bfbe22 commit 40869d4

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.rst

+36
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,42 @@ You can be creative with these variables: e.g. a context processor could
103103
set a default CSS error class on all fields rendered by
104104
``{% render_field %}``.
105105

106+
In addition, it is possible to dynamically set attributes using a variable of type dict from context
107+
and setting it equal to ``attr_dict``. The content of ``attr_dict`` its order around explicitly named
108+
attributes matters; it is possible to set a default attribute that will be overwritten by ``attr_dict``
109+
by positioning it to the left, or conversely to have an attribute always overwrite one in ``attr_dict``
110+
by positioning it to the right.
111+
112+
Examples:
113+
114+
Let context_dict_var be:
115+
116+
.. code-block:: html+django
117+
118+
context_dict_var = {"type":"text", id="my_username_id", placeholder="Login"}
119+
120+
The following line:
121+
.. code-block:: html+django
122+
123+
{% render_field form.field attr_dict=context_dict %}
124+
125+
returns:
126+
127+
.. code-block:: html+django
128+
129+
<input type="text" id="my_field_id" placeholder="Input here" />
130+
131+
The following line:
132+
.. code-block:: html+django
133+
134+
{% render_field form.field id="default_id" label="default_label" attr_dict=context_dict placeholder="Overwrite" %}
135+
136+
returns:
137+
138+
.. code-block:: html+django
139+
140+
<input type="text" id="default_id" label="default_label" placeholder="Overwrite" />
141+
106142
attr
107143
----
108144
Adds or replaces any single html attribute for the form field.

0 commit comments

Comments
 (0)