by default, don't set id attribute for hidden inputs tls-sprint
authorsylvain.thenault@logilab.fr
Tue, 10 Mar 2009 15:39:53 +0100
branchtls-sprint
changeset 1032 25ec009daa95
parent 1031 1a89683cb687
child 1033 f5be65616a31
by default, don't set id attribute for hidden inputs
web/form.py
--- a/web/form.py	Tue Mar 10 15:39:23 2009 +0100
+++ b/web/form.py	Tue Mar 10 15:39:53 2009 +0100
@@ -255,9 +255,13 @@
 class FieldWidget(object):
     needs_js = ()
     needs_css = ()
+    setdomid = True
     
-    def __init__(self, attrs=None):
+    def __init__(self, attrs=None, setdomid=None):
         self.attrs = attrs or {}
+        if setdomid is not None:
+            # override class's default value
+            self.setdomid = setdomid
 
     def add_media(self, form):
         """adds media (CSS & JS) required by this widget"""
@@ -276,7 +280,8 @@
         if not isinstance(values, (tuple, list)):
             values = (values,)
         attrs = dict(self.attrs)
-        attrs['id'] = form.context[field]['id']
+        if self.setdomid:
+            attrs['id'] = form.context[field]['id']
         return name, values, attrs
 
 class Input(FieldWidget):
@@ -316,6 +321,7 @@
         
 class HiddenInput(Input):
     type = 'hidden'
+    setdomid = False # by default, don't set id attribute on hidden input
     
 class ButtonInput(Input):
     type = 'button'