You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to render some formfields and pass attributes via the template, to be passed to the widget, as I understood you could from the docs. It doesn't seem to be working. For example if I create a form like
{% load floppyforms %}
<!doctype html><html><body>
{% form test_form using %}
{% formfield form.test_input with placeholder="foo" %}
{% formconfig field with placeholder="bar" for "second_input" %}
{% formfield form.second_input %}
{% endform %}
</body></html>
I would expect each field to get a placeholder. I did this to illustrate 2 different methods of passing the attribute I read in the docs, yet neither seems to work. Am I doing it wrong?
The text was updated successfully, but these errors were encountered:
Hi I think there is a misunderstanding of what the arguments after with are doing.
With with you can pass additional template variables into the template that is used to render the widget. The template is then responsible for rendering those template variables into actual attributes of the widget. So to make your example work, you would need to overwrite the template floppyforms/input.html with the following content:
<inputtype="{{ type }}"name="{{ name }}"{%ifvalue%}value="{{ value }}"{%endif%}{%ifrequired%}required{%endif%}{%include"floppyforms/attrs.html"%}{%ifdatalist%}list="{{ attrs.id }}_list"{%endif%}{%ifplaceholder%}placeholder="{{ placeholder }}"{%endif%}>{%ifdatalist%}
<datalistid="{{ attrs.id }}_list">{%foritemindatalist%}
<optionvalue="{{ item }}">{%endfor%}
</datalist>{%endif%}
Please especially note the section: {% if placeholder %} placeholder="{{ placeholder }}"{% endif %} which I have added.
The documentation should probably be updated then, as both the sections about formconfig and formfield are saying that my original implementation would work.
However, even if I pass a dict called attrs that looks like {'placeholder':'foo'}, that looks like it should be getting passed to attrs.html and written out, correct? The reason I'm having trouble is that it's going to be quite difficult for me to determine in the template which formfield template I need to use (input, select, etc.), as I'm just making a generic formrow template, and want to pass through things like placeholders and classnames
I'm trying to render some formfields and pass attributes via the template, to be passed to the widget, as I understood you could from the docs. It doesn't seem to be working. For example if I create a form like
and a template like
I would expect each field to get a placeholder. I did this to illustrate 2 different methods of passing the attribute I read in the docs, yet neither seems to work. Am I doing it wrong?
The text was updated successfully, but these errors were encountered: