changeset 218:fd36d76dd0e3

util.forms: new filter for required attributes added, thanks to Jason Kirtland
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 07 May 2011 22:10:41 +0200
parents 60242b1ba235
children 96b17384932a
files MoinMoin/util/forms.py
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/util/forms.py	Sat May 07 20:23:40 2011 +0200
+++ b/MoinMoin/util/forms.py	Sat May 07 22:10:41 2011 +0200
@@ -34,6 +34,12 @@
     return contents
 button_filter.tags = set(['input', 'button'])
 
+def required_filter(tagname, attributes, contents, context, bind):
+    if (bind is not None and not bind.optional):
+        attributes[u'class'] = u'required'
+        attributes[u'required'] = u'required'
+    return contents
+required_filter.tags = set(['input', 'label'])
 
 def error_filter_factory(class_='moin-error'):
     """Returns an HTML generation filter annotating field CSS class on error.
@@ -58,5 +64,6 @@
     """make an html generator"""
     return Generator(auto_domid=True, auto_for=True, auto_filter=True,
                      markup_wrapper=Markup,
-                     filters=[label_filter, button_filter, error_filter])
+                     filters=[label_filter, button_filter,
+                              error_filter, required_filter])