Mike Orr avatar Mike Orr committed f8fd569

Don't add an "id" attribute to hidden tags generated by render().

Comments (0)

Files changed (3)

     ``literal``. Compatibility should not be a problem; but see the docs if
     you encounter any edge cases.
 
+* webhelpers.html.tags:
+
+  - 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.
+
 1.1 (2010-08-09)
 ----------------
 

docs/whats_new.rst

 Version 1.2
 -----------
 
-*webhelpers.html*: The HTML builder now uses Armin Ronacher's
+*webhelpers.html:* The HTML builder now uses Armin Ronacher's
 "MarkupSafe" package, which Mako and Pylons have also switched to.  MarkupSafe
 has a C speedup for escaping, escapes single-quotes for greater security (to
 close a potential XSS attack route), and adds new methods to ``literal``.
 *Note*: ``escape_silent`` does not exist yet in MarkupSafe 0.9.3, but
 WebHelpers has a fallback. 
 
+*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.
+
 Version 1.1
 -----------
 

webhelpers/html/tags.py

     >>> form("/submit", method="get")
     literal(u'<form action="/submit" method="get">')
     >>> form("/submit", method="put")
-    literal(u'<form action="/submit" method="post"><div style="display:none">\\n<input id="_method" name="_method" type="hidden" value="put" />\\n</div>\\n')
+    literal(u'<form action="/submit" method="post"><div style="display:none">\\n<input name="_method" type="hidden" value="put" />\\n</div>\\n')
     >>> form("/submit", "post", multipart=True) 
     literal(u'<form action="/submit" enctype="multipart/form-data" method="post">')
 
-    Changed in WebHelpers 2.0b2: add <div> and ``hidden_fields`` arg.
+    Changed in WebHelpers 1.0b2: add <div> and ``hidden_fields`` arg.
+
+    Changed in WebHelpers 1.2: don't add an "id" attribute to hidden tags
+    generated by this helper; they clash if there are multiple forms on the
+    page.
     """
     fields = []
     attrs["action"] = url
         attrs['method'] = method
     else:
         attrs['method'] = "post"
-        field = hidden("_method", method)
+        field = hidden("_method", method, id=None)
         fields.append(field)
     if hidden_fields is not None:
         try:
         except AttributeError:
             it = hidden_fields
         for name, value in it:
-            field = hidden(name, value)
+            field = hidden(name, value, id=None)
             fields.append(field)
     if fields:
         div = HTML.div(style="display:none", _nl=True, *fields)
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.