Hey Russ,

I think this is a great proposal so far!

Is there a way with the proposed solution for the template designer to
add custom attributes to a form field? If so, do you envision that
happening in the chrome layer?

Here's a use case:

The designer wants to render an email input field. They also want to
set the ``autocapitalize`` attribute to "off" so Mobile Safari doesn't
capitalize the first letter of the email while it's being typed. In
addition, they want to set the placeholder attribute.


Internally, we solve this problem through a custom template tag doing
something like this:

Form Template::

    {% load form_tags %}

    {% with "forms/text_field.html" as text_field_template %}
      {% text_field form.email placeholder="Email"
autocapitalize="off" autocorrect="off" %}
    {% endwith %}

Field Template::

    <span{% if field.errors %} class="field-error"{% endif %}>
      {{ field }}
    </span>


We use the template tag because calling
``form_field.field.widget.attrs.update(attrs)`` is the only way I know
to get the {{ field }} object to render custom attributes on the input
field from the template. Other use cases involve overriding the label
defined in the form definition and adding custom classes to the input
field.

Thanks,

Preston

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to