Discussion:
[FE-discuss] htmlfill question
Jonathan Vanasco
2012-02-04 20:11:04 UTC
Permalink
i'm a little confused by htmlfill's behavior on this.

Given a form like this:
<form:error name="Error_Main"/>
<input id="login-email_address" name="email_address" placeholder="Email Address" size="30" type="text" />
<input id="login-password" name="password" placeholder="Password" size="30" type="password" />

and a call to htmlfill with this:
formencode.htmlfill.render(\
form_content,
defaults=defaults,
errors=errors,
auto_error_formatter=custom_formatter
)

My output is essentially this:
Error Main -- rendered with default formatter
email_address -- rendered with custom formatter
password -- rendered with custom formatter

anyone have an idea to get the Error_Main section to render with the custom formatter along with the other fields (aside from specifying a custom renderer in the field and passing in a dict )?
Chris Lambacher
2012-02-05 15:42:38 UTC
Permalink
You should be able to use the formatter attribute to specify a custom
formatter:
http://www.formencode.org/en/latest/htmlfill.html#errors:
<form:error name="field_name" format="formatter">

You will also need to provide the error_formatters argument to renderer if
the formatter you want to use is not one of the default ones:
http://www.formencode.org/en/latest/modules/htmlfill.html#formencode.htmlfill.render

-Chris
Post by Jonathan Vanasco
i'm a little confused by htmlfill's behavior on this.
<form:error name="Error_Main"/>
<input id="login-email_address" name="email_address"
placeholder="Email Address" size="30" type="text" />
<input id="login-password" name="password" placeholder="Password"
size="30" type="password" />
formencode.htmlfill.render(\
form_content,
defaults=defaults,
errors=errors,
auto_error_formatter=custom_formatter
)
Error Main -- rendered with default formatter
email_address -- rendered with custom formatter
password -- rendered with custom formatter
anyone have an idea to get the Error_Main section to render with the
custom formatter along with the other fields (aside from specifying a
custom renderer in the field and passing in a dict )?
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
FormEncode-discuss mailing list
https://lists.sourceforge.net/lists/listinfo/formencode-discuss
--
Christopher Lambacher
***@kateandchris.net
Jonathan Vanasco
2012-02-22 23:52:11 UTC
Permalink
Thanks Chris.

I knew about being able to specify & pass custom formatters. I wanted to avoid that, and rely on the auto error. I guess i wanted a clue on how to patch formencode.

My issue is with the behavior I illustrated below, which I would consider a bug.

One would assume that if you pass in the "auto_error_formatter" argument, it would be used for generating ALL errors. Instead it generates errors only for html input type elements, and does not format the form:error blocks.
Post by Chris Lambacher
<form:error name="field_name" format="formatter">
http://www.formencode.org/en/latest/modules/htmlfill.html#formencode.htmlfill.render
-Chris
i'm a little confused by htmlfill's behavior on this.
<form:error name="Error_Main"/>
<input id="login-email_address" name="email_address" placeholder="Email Address" size="30" type="text" />
<input id="login-password" name="password" placeholder="Password" size="30" type="password" />
formencode.htmlfill.render(\
form_content,
defaults=defaults,
errors=errors,
auto_error_formatter=custom_formatter
)
Error Main -- rendered with default formatter
email_address -- rendered with custom formatter
password -- rendered with custom formatter
anyone have an idea to get the Error_Main section to render with the custom formatter along with the other fields (aside from specifying a custom renderer in the field and passing in a dict )?
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
FormEncode-discuss mailing list
https://lists.sourceforge.net/lists/listinfo/formencode-discuss
--
Christopher Lambacher
// Jonathan Vanasco

c. 646.729.6436 | 415.501.9815
e. ***@2xlp.com
w. http://findmeon.com/user/jvanasco
linkedin. http://linkedin.com/in/jonathanvanasco
blog. http://destructuring.net
Chris Lambacher
2012-02-23 02:38:33 UTC
Permalink
Hi Jonathan,

So I think the issue here is that the docs could be more clear:

auto_error_formatter is used to create the HTML that goes above the fields.
By default it wraps the error message in a span and adds a <br>.

In this text "is used to create the HTML that goes above the fields" is a
reference to the docs for the auto_insert_errors docs:

If auto_insert_errors is true (the default) then any errors for which
<form:error> tags can’t be found will be put just above the associated
input field, or at the top of the form if no field can be found.

The docs there clearly indicate that the "auto_insert_errors" argument is
explicitly talking about errors that *don't* have a <form:error> tag. In
your case you *do* have a form error tag and if you want to override the
default formatter in that case then you need to set something in the
"error_formatters" argument. In other words, "auto_error_formatter" is not
a global catch all formatter for all errors, it is a catch all for errors
that don't have a "<form:error>" tag.

If you want to override the default formatter for "<form:error>" tags, pass
in error_formatters as {'default': my_formatter} and you will be off to the
races.

If you want to have a global default for your project, I recommend that you
write and use a wrapper function that provides the defaults you want while
passing through the parameters that you need to change regularly.

-Chris
Post by Jonathan Vanasco
Thanks Chris.
I knew about being able to specify & pass custom formatters. I wanted to
avoid that, and rely on the auto error. I guess i wanted a clue on how to
patch formencode.
My issue is with the behavior I illustrated below, which I would consider a bug.
One would assume that if you pass in the "auto_error_formatter" argument,
it would be used for generating ALL errors. Instead it generates errors
only for html input type elements, and does not format the form:error
blocks.
<form:error name="field_name" format="formatter">
You will also need to provide the error_formatters argument to renderer if
http://www.formencode.org/en/latest/modules/htmlfill.html#formencode.htmlfill.render
-Chris
Post by Jonathan Vanasco
i'm a little confused by htmlfill's behavior on this.
<form:error name="Error_Main"/>
<input id="login-email_address" name="email_address"
placeholder="Email Address" size="30" type="text" />
<input id="login-password" name="password" placeholder="Password"
size="30" type="password" />
formencode.htmlfill.render(\
form_content,
defaults=defaults,
errors=errors,
auto_error_formatter=custom_formatter
)
Error Main -- rendered with default formatter
email_address -- rendered with custom formatter
password -- rendered with custom formatter
anyone have an idea to get the Error_Main section to render with the
custom formatter along with the other fields (aside from specifying a
custom renderer in the field and passing in a dict )?
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
FormEncode-discuss mailing list
https://lists.sourceforge.net/lists/listinfo/formencode-discuss
--
Christopher Lambacher
// Jonathan Vanasco
c. 646.729.6436 | 415.501.9815
w. http://findmeon.com/user/jvanasco
linkedin. http://linkedin.com/in/jonathanvanasco
blog. http://destructuring.net
--
Christopher Lambacher
***@kateandchris.net
Loading...