diff MoinMoin/util/forms.py @ 226:029cb888d253

use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 14 May 2011 17:39:38 +0200
parents fd36d76dd0e3
children c956811fba9a
line wrap: on
line diff
--- a/MoinMoin/util/forms.py	Mon May 09 23:58:03 2011 +0200
+++ b/MoinMoin/util/forms.py	Sat May 14 17:39:38 2011 +0200
@@ -41,6 +41,22 @@
     return contents
 required_filter.tags = set(['input', 'label'])
 
+def autofocus_filter(tagname, attributes, contents, context, bind):
+    if bind is not None:
+        autofocus = bind.properties.get('autofocus')
+        if autofocus:
+            attributes[u'autofocus'] = u'autofocus'
+    return contents
+required_filter.tags = set(['input', 'textarea', ])
+
+def placeholder_filter(tagname, attributes, contents, context, bind):
+    if bind is not None:
+        placeholder = bind.properties.get('placeholder')
+        if placeholder:
+            attributes[u'placeholder'] = placeholder
+    return contents
+required_filter.tags = set(['input', 'textarea', ])
+
 def error_filter_factory(class_='moin-error'):
     """Returns an HTML generation filter annotating field CSS class on error.
 
@@ -65,5 +81,6 @@
     return Generator(auto_domid=True, auto_for=True, auto_filter=True,
                      markup_wrapper=Markup,
                      filters=[label_filter, button_filter,
-                              error_filter, required_filter])
+                              error_filter,
+                              required_filter, placeholder_filter, autofocus_filter])