Commits

Mike Orr committed 0138841

Add "type" argument to ``text()`` for new HTML 5 input types.

  • Participants
  • Parent commits f8fd569

Comments (0)

Files changed (3)

 
 * webhelpers.html.tags:
 
+  - For new HTML 5 input fields, the ``text`` helper has a "type" argument.
+
   - Don't put an "id" attribute on a hidden fields generated by the ``form()``
     helper, including the magic ``_method`` field. The IDs will clash if there
     are multiple forms on the page.

docs/whats_new.rst

 *Note*: ``escape_silent`` does not exist yet in MarkupSafe 0.9.3, but
 WebHelpers has a fallback. 
 
+*webhelpers.html.tags:* The ``text()`` helper has a "type" argument for new
+HTML 5 input types.
+
 *webhelpers.html.tags:* **Don't add an "id" attribute to hidden fields
 generated by the ``form()`` helper**: the IDs clash if there are multiple forms
 on the page. To create a hidden field with an ID, call ``hidden()`` directly.

webhelpers/html/tags.py

     return literal("</form>")
 
 
-def text(name, value=None, id=NotGiven, **attrs):
+def text(name, value=None, id=NotGiven, type="text", **attrs):
     """Create a standard text field.
     
     ``value`` is a string, the content of the text field.
     ``_make_safe_id_component()``.  Pass None to suppress the
     ID attribute entirely.
 
+    ``type`` is the input field type, normally "text". You can override it
+    for HTML 5 input fields that don't have their own helper; e.g.,
+    "search", "email", "date".
+
     
     Options:
     
         will allow the user to enter.
     
     The remaining keyword args will be standard HTML attributes for the tag.
+
+    Example, a text input field::
+
+        >>> text("address")
+        literal(u'<input id="address" name="address" type="text" />')
+
+    HTML 5 example, a color picker:
+
+        >>> text("color", type="color")
+        literal(u'<input id="color" name="color" type="color" />')
     
     """
-    _set_input_attrs(attrs, "text", name, value)
+    _set_input_attrs(attrs, type, name, value)
     _set_id_attr(attrs, id, name)
     convert_boolean_attrs(attrs, ["disabled"])
     return HTML.input(**attrs)