File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,42 @@ You can be creative with these variables: e.g. a context processor could
103103set 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+
106142attr
107143----
108144Adds or replaces any single html attribute for the form field.
You can’t perform that action at this time.
0 commit comments