Mike Orr avatar Mike Orr committed 642d765

Change 'id' argument behavior for input tags.

Comments (0)

Files changed (2)

 tip (development version)
 -------------------------
 
-No changes yet.
+* webhelpers.html.tags:
 
-
-1.0rc1 (2010-05-24)
--------------------
-
-* webhelpers.containers:
-
- - ``get_many()``: Extract several values from a dict to unpack into simple
-   variables, allowing optional keys while still returning values in a 
-   predictable order. Contributed by Shazow.
-
-* webhelpers.feedgenerator:
-
- - Allow ``RssFeed`` base class to be instantiated. However, it sets the RSS
-   version attribute to "?", which is probably invalid.
-
-* webhelpers.html.grid  / webhelpers.pylonslib.grid:
-
- - A new ``ListGrid`` class to turn a list of lists into a table.
- - Bugfixes by Ergo.
+ - Change 'id' argument to all helpers. The default value is now NotGiven
+   rather than None. NotGiven tells WebHelpers to create an ID attribute based 
+   on the field name (formerly None did this). None suppresses the ID attribute
+   entirely (formerly "" did this, and still does for backward compatibility).
+   This behavior of None is consistent with other parts of WebHelpers.
 
 * webhelpers.misc:
 
  - New ``format_exception`` helper to display an exception as Python would but
    without the traceback.
 
-* webhelpers.number:
-
-  - Bugfix in format_data_size and derivatives if size <= 0. Found by
-    Marcin Kuzminski.
-
 1.0b7 (2010-05-16)
 ------------------
 

webhelpers/html/tags.py

 e.g., ``class_``.  Some helpers handle certain keywords specially; these are
 noted in the helpers' docstrings.
 
-to create your own custom tags, see ``webhelpers.html.builder``.
+To create your own custom tags, see ``webhelpers.html.builder``.
 
 A set of CSS styles complementing these helpers is in
 ``webhelpers/public/stylesheets/webhelpers.css``.
 from webhelpers import containers
 from webhelpers.html import escape, HTML, literal, url_escape
 import webhelpers.media as media
+from webhelpers.misc import NotGiven
 
 __all__ = [
            # Form tags
     return literal("</form>")
 
 
-def text(name, value=None, id=None, **attrs):
+def text(name, value=None, id=NotGiven, **attrs):
     """Create a standard text field.
     
     ``value`` is a string, the content of the text field.
 
     ``id`` is the HTML ID attribute, and should be passed as a keyword
     argument.  By default the ID is the same as the name filtered through
-    ``_make_safe_id_component()``.  Pass the empty string ("") to suppress the
+    ``_make_safe_id_component()``.  Pass None to suppress the
     ID attribute entirely.
 
     
     return HTML.input(**attrs)
 
 
-def hidden(name, value=None, id=None, **attrs):
+def hidden(name, value=None, id=NotGiven, **attrs):
     """Create a hidden field.
     """
     _set_input_attrs(attrs, "hidden", name, value)
     return HTML.input(**attrs)
 
 
-def file(name, value=None, id=None, **attrs):
+def file(name, value=None, id=NotGiven, **attrs):
     """Create a file upload field.
     
     If you are using file uploads then you will also need to set the 
     return HTML.input(**attrs)
 
 
-def password(name, value=None, id=None, **attrs):
+def password(name, value=None, id=NotGiven, **attrs):
     """Create a password field.
     
     Takes the same options as ``text()``.
     return HTML.input(**attrs)
 
 
-def textarea(name, content="", id=None, **attrs):
+def textarea(name, content="", id=NotGiven, **attrs):
     """Create a text input area.
     
     Example::
     return HTML.textarea(content, **attrs)
 
 
-def checkbox(name, value="1", checked=False, label=None, id=None, **attrs):
+def checkbox(name, value="1", checked=False, label=None, id=NotGiven, **attrs):
     """Create a check box.
 
     Arguments:
 
     ``id`` is the HTML ID attribute, and should be passed as a keyword
     argument.  By default the ID is the same as the name filtered through
-    ``_make_safe_id_component()``.  Pass the empty string ("") to suppress the
+    ``_make_safe_id_component()``.  Pass None to suppress the
     ID attribute entirely.
 
     The following HTML attributes may be set by keyword argument:
     return widget
 
 
-def submit(name, value, id=None, **attrs):
+def submit(name, value, id=NotGiven, **attrs):
     """Create a submit button with the text ``value`` as the caption."""
     _set_input_attrs(attrs, "submit", name, value)
     _set_id_attr(attrs, id, name)
     return HTML.input(**attrs)
 
 
-def select(name, selected_values, options, id=None, **attrs):
+def select(name, selected_values, options, id=NotGiven, **attrs):
     """Create a dropdown selection box.
 
     * ``name`` -- the name of this control.
 
     ``id`` is the HTML ID attribute, and should be passed as a keyword
     argument.  By default the ID is the same as the name.  filtered through
-    ``_make_safe_id_component()``.  Pass the empty string ("") to suppress the
+    ``_make_safe_id_component()``.  Pass None to suppress the
     ID attribute entirely.
 
 
     attrs["name"] = name
     attrs["value"] = value
 
-def _set_id_attr(attrs, id, name):
-    if "id_" in attrs and id is not None:
-        raise TypeError("can't pass both 'id' and 'id_' arguments")
-    elif "id_" in attrs:
+def _set_id_attr(attrs, id_arg, name):
+    if "id_" in attrs:
+        if id_arg is not NotGiven:
+            raise TypeError("can't pass both 'id' and 'id_' args to helper")
         attrs["id"] = attrs.pop("id_")
-    elif id is None:
+    elif id_arg is NotGiven:
         attrs["id"] = _make_safe_id_component(name)
-    elif id != "":
-        attrs["id"] = id
+    elif id_arg is not None and id_arg != "":
+        attrs["id"] = id_arg
+    # Else id_arg is None or "", so do nothing.
 
 def _make_safe_id_component(idstring):
     """Make a string safe for including in an id attribute.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.