Author: ianb
Date: 2008-04-10 02:19:18 -0600 (Thu, 10 Apr 2008)
New Revision: 3374

Modified:
   FormEncode/trunk/docs/news.txt
   FormEncode/trunk/formencode/htmlfill.py
Log:
Added prefix_error option to htmlfill.render

Modified: FormEncode/trunk/docs/news.txt
===================================================================
--- FormEncode/trunk/docs/news.txt      2008-04-09 13:19:11 UTC (rev 3373)
+++ FormEncode/trunk/docs/news.txt      2008-04-10 08:19:18 UTC (rev 3374)
@@ -3,6 +3,13 @@
 
 .. contents::
 
+svn trunk
+---------
+
+* Added a parameter to ``htmlfill.render()``: ``prefix_error``.  If
+  this parameter is true (the default) then errors automatically go
+  before the input field; if false then they go after the input field.
+
 1.0.1
 -----
 

Modified: FormEncode/trunk/formencode/htmlfill.py
===================================================================
--- FormEncode/trunk/formencode/htmlfill.py     2008-04-09 13:19:11 UTC (rev 
3373)
+++ FormEncode/trunk/formencode/htmlfill.py     2008-04-10 08:19:18 UTC (rev 
3374)
@@ -16,7 +16,7 @@
            error_formatters=None, add_attributes=None,
            auto_insert_errors=True, auto_error_formatter=None,
            text_as_default=False, listener=None, encoding=None,
-           error_class='error'):
+           error_class='error', prefix_error=True):
     """
     Render the ``form`` (which should be a string) given the defaults
     and errors.  Defaults are the values that go in the input fields
@@ -57,6 +57,9 @@
     
     ``encoding`` specifies an encoding to assume when mixing str and 
     unicode text in the template.
+    
+    ``prefix_error`` specifies if the HTML created by auto_error_formatter is
+    put before the input control (default) or after the control.
     """
     if defaults is None:
         defaults = {}
@@ -70,6 +73,7 @@
         auto_error_formatter=auto_error_formatter,
         text_as_default=text_as_default,
         listener=listener, encoding=encoding,
+        prefix_error=prefix_error,
         error_class=error_class,
         )
     p.feed(form)
@@ -172,7 +176,7 @@
                  error_formatters=None, error_class='error',
                  add_attributes=None, listener=None,
                  auto_error_formatter=None,
-                 text_as_default=False, encoding=None):
+                 text_as_default=False, encoding=None, prefix_error=True):
         HTMLParser.HTMLParser.__init__(self)
         self._content = []
         self.source = None
@@ -200,6 +204,10 @@
         self.auto_error_formatter = auto_error_formatter
         self.text_as_default = text_as_default
         self.encoding = encoding
+        if prefix_error:
+            self._marker_offset = 0
+        else:
+            self._marker_offset = 2
 
     def feed(self, data):
         self.data_is_str = isinstance(data, str)
@@ -519,9 +527,10 @@
         self._content.append((marker,))
 
     def insert_at_marker(self, marker, text):
+         
         for i, item in enumerate(self._content):
             if item == (marker,):
-                self._content.insert(i, text)
+                self._content.insert(i  + self._marker_offset, text)
                 break
         else:
             self._content.insert(0, text)


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
FormEncode-CVS mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-cvs

Reply via email to