Re: htmlfill question
Chris Lambacher <[email protected]> Wed, 22 Feb 2012 21:38:33 -0500
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <CAAXXHgKsfOGxgfVf3xk1yrXWqZ3h0VR8A-7FHz4rXi2Dr-2Tqw@mail.gmail.com> |
--===============7665262677042375534==
Content-Type: multipart/alternative; boundary=e0cb4efe34dc4d562404b9988a5d
--e0cb4efe34dc4d562404b9988a5d
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
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=E2=80=99t be found will be put just above the associa=
ted
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
On Wed, Feb 22, 2012 at 6:52 PM, Jonathan Vanasco <[email protected]> wrote=
:
> 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 t=
o
> 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.
>
> On Feb 5, 2012, at 10:42 AM, Chris Lambacher wrote:
>
> 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=3D"field_name" format=3D"formatter">
>
> You will also need to provide the error_formatters argument to renderer i=
f
> the formatter you want to use is not one of the default ones:
>
> http://www.formencode.org/en/latest/modules/htmlfill.html#formencode.html=
fill.render
>
> -Chris
>
> On Sat, Feb 4, 2012 at 3:11 PM, Jonathan Vanasco <[email protected]>wrote=
:
>
>>
>> i'm a little confused by htmlfill's behavior on this.
>>
>> Given a form like this:
>> <form:error name=3D"Error_Main"/>
>> <input id=3D"login-email_address" name=3D"email_address"
>> placeholder=3D"Email Address" size=3D"30" type=3D"text" />
>> <input id=3D"login-password" name=3D"password" placeholder=3D"Passwo=
rd"
>> size=3D"30" type=3D"password" />
>>
>> and a call to htmlfill with this:
>> formencode.htmlfill.render(\
>> form_content,
>> defaults=3Ddefaults,
>> errors=3Derrors,
>> auto_error_formatter=3Dcustom_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 )?
>>
>> ------------------------------------------------------------------------=
------
>> Try before you buy =3D 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
>> FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
>> https://lists.sourceforge.net/lists/listinfo/formencode-discuss
>>
>
>
>
> --
> Christopher Lambacher
> [email protected]
>
>
> // Jonathan Vanasco
>
> c. 646.729.6436 | 415.501.9815
> e. [email protected]
> w. http://findmeon.com/user/jvanasco
> linkedin. http://linkedin.com/in/jonathanvanasco
> blog. http://destructuring.net
>
>
--=20
Christopher Lambacher
[email protected]
--e0cb4efe34dc4d562404b9988a5d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div class=3D"gmail_quote">Hi Jonathan,</div><div class=3D"gmail_quote"><br=
></div><div class=3D"gmail_quote"><div>So I think the issue here is that th=
e docs could be more clear:</div><div><br></div><div><tt class=3D"docutils =
literal" style=3D"font-family:Consolas,'Deja Vu Sans Mono','Bit=
stream Vera Sans Mono',monospace;font-size:0.95em;background-color:rgb(=
242,242,242);color:rgb(68,68,68);text-align:left"><span class=3D"pre">auto_=
error_formatter</span></tt><span style=3D"font-family:ff-meta-web-pro-1,ff-=
meta-web-pro-2,Arial,'Helvetica Neue',sans-serif;font-size:16px;lin=
e-height:24px;text-align:left;background-color:rgb(255,255,255)">=C2=A0is u=
sed to create the HTML that goes above the fields. By default it wraps the =
error message in a span and adds a=C2=A0</span><tt class=3D"docutils litera=
l" style=3D"font-family:Consolas,'Deja Vu Sans Mono','Bitstream=
Vera Sans Mono',monospace;font-size:0.95em;background-color:rgb(242,24=
2,242);color:rgb(68,68,68);text-align:left"><span class=3D"pre"><br><=
/span></tt><span style=3D"font-family:ff-meta-web-pro-1,ff-meta-web-pro-2,A=
rial,'Helvetica Neue',sans-serif;font-size:16px;line-height:24px;te=
xt-align:left;background-color:rgb(255,255,255)">.</span></div>
<div><br></div><div>In this text "is used to create the HTML that goes=
above the fields" is a reference to the docs for the auto_insert_erro=
rs docs:</div><div><br></div><div><span style=3D"font-family:ff-meta-web-pr=
o-1,ff-meta-web-pro-2,Arial,'Helvetica Neue',sans-serif;font-size:1=
6px;line-height:24px;text-align:left;background-color:rgb(255,255,255)">If=
=C2=A0</span><tt class=3D"docutils literal" style=3D"font-family:Consolas,&=
#39;Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;fon=
t-size:0.95em;background-color:rgb(242,242,242);color:rgb(68,68,68);text-al=
ign:left"><span class=3D"pre">auto_insert_errors</span></tt><span style=3D"=
font-family:ff-meta-web-pro-1,ff-meta-web-pro-2,Arial,'Helvetica Neue&#=
39;,sans-serif;font-size:16px;line-height:24px;text-align:left;background-c=
olor:rgb(255,255,255)">=C2=A0is true (the default) then any errors for whic=
h=C2=A0</span><tt class=3D"docutils literal" style=3D"font-family:Consolas,=
'Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;fo=
nt-size:0.95em;background-color:rgb(242,242,242);color:rgb(68,68,68);text-a=
lign:left"><span class=3D"pre"><form:error></span></tt><span style=3D=
"font-family:ff-meta-web-pro-1,ff-meta-web-pro-2,Arial,'Helvetica Neue&=
#39;,sans-serif;font-size:16px;line-height:24px;text-align:left;background-=
color:rgb(255,255,255)">=C2=A0tags can=E2=80=99t be found will be put just =
above the associated input field, or at the top of the form if no field can=
be found.</span></div>
<div><br></div><div>The docs there clearly indicate that the "auto_ins=
ert_errors" argument is explicitly talking about errors that *don'=
t* have a <form:error> tag. In your case you *do* have a form error t=
ag and if you want to override the default formatter in that case then you =
need to set something in the "error_formatters" argument. In othe=
r words, "auto_error_formatter" is not a global catch all formatt=
er for all errors, it is a catch all for errors that don't have a "=
;<form:error>" tag.</div>
<div><br></div><div>If you want to override the default formatter for "=
;<form:error>" tags, pass in error_formatters as {'default&#=
39;: my_formatter} and you will be off to the races.=C2=A0</div><div><br></=
div>
<div>If you want to have a global default for your project, I recommend tha=
t you write and use a wrapper function that provides the defaults you want =
while passing through the=C2=A0parameters=C2=A0that you need to change regu=
larly.</div>
<div><br></div><div>-Chris</div></div><div class=3D"gmail_quote"><br></div>=
<div class=3D"gmail_quote">On Wed, Feb 22, 2012 at 6:52 PM, Jonathan Vanasc=
o <span dir=3D"ltr"><<a href=3D"mailto:[email protected]">jvanasco@2xlp.=
com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div style=3D"word-wrap:break-word">Thanks C=
hris.<div><br></div><div>I knew about being able to specify & pass cust=
om formatters. =C2=A0I wanted to avoid that, and rely on the auto error. =
=C2=A0I guess i wanted a clue on how to patch formencode.</div>
<div><br></div><div>My issue is with the behavior I illustrated below, whic=
h I would consider a bug.</div><div><br></div><div>One would assume that if=
you pass in the "auto_error_formatter" argument, it would be use=
d for generating ALL errors. =C2=A0Instead it generates errors only for htm=
l input type elements, and does not format the form:error blocks.</div>
</div></blockquote><div><br></div><div><br></div><blockquote class=3D"gmail=
_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:=
1ex"><div style=3D"word-wrap:break-word"><div><br></div><div><div><div clas=
s=3D"h5">
<div><div>On Feb 5, 2012, at 10:42 AM, Chris Lambacher wrote:</div><br><blo=
ckquote type=3D"cite">You should be able to use the formatter attribute to =
specify a custom formatter:<div><span style=3D"color:rgb(68,68,68);font-fam=
ily:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono'=
,monospace;font-size:15px;line-height:22px;text-align:left;background-color=
:rgb(242,242,242)"><a href=3D"http://www.formencode.org/en/latest/htmlfill.=
html#errors" target=3D"_blank">http://www.formencode.org/en/latest/htmlfill=
.html#errors</a>:</span></div>
<div><span style=3D"color:rgb(68,68,68);font-family:Consolas,'Deja Vu S=
ans Mono','Bitstream Vera Sans Mono',monospace;font-size:15px;l=
ine-height:22px;text-align:left;background-color:rgb(242,242,242)"><form=
:error</span><span style=3D"color:rgb(68,68,68);font-family:Consolas,'D=
eja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;font-siz=
e:15px;line-height:22px;text-align:left;background-color:rgb(242,242,242)">=
=C2=A0</span><span style=3D"color:rgb(68,68,68);font-family:Consolas,'D=
eja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;font-siz=
e:15px;line-height:22px;text-align:left;background-color:rgb(242,242,242)">=
name=3D"field_name"</span><span style=3D"color:rgb(68,68,68);font=
-family:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono&=
#39;,monospace;font-size:15px;line-height:22px;text-align:left;background-c=
olor:rgb(242,242,242)">=C2=A0</span><span style=3D"color:rgb(68,68,68);font=
-family:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono&=
#39;,monospace;font-size:15px;line-height:22px;text-align:left;background-c=
olor:rgb(242,242,242)">format=3D"formatter"></span>=C2=A0</div=
>
<div><br></div><div>You will also need to provide the error_formatters argu=
ment to renderer if the formatter you want to use is not one of the default=
ones:</div><div><a href=3D"http://www.formencode.org/en/latest/modules/htm=
lfill.html#formencode.htmlfill.render" target=3D"_blank">http://www.formenc=
ode.org/en/latest/modules/htmlfill.html#formencode.htmlfill.render</a>
</div><div><br>-Chris</div><div><br><div class=3D"gmail_quote">On Sat, Feb =
4, 2012 at 3:11 PM, Jonathan Vanasco <span dir=3D"ltr"><<a href=3D"mailt=
o:[email protected]" target=3D"_blank">[email protected]</a>></span> wro=
te:<br>
<blockquote class=3D"gmail_quote" style=3D"margin-top:0px;margin-right:0px;=
margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color=
:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
i'm a little confused by htmlfill's behavior on this.<br>
<br>
Given a form like this:<br>
=C2=A0 =C2=A0 <form:error name=3D"Error_Main"/><br>
=C2=A0 =C2=A0 <input id=3D"login-email_address" name=3D"=
email_address" placeholder=3D"Email Address" size=3D"30=
" type=3D"text" /><br>
=C2=A0 =C2=A0 <input id=3D"login-password" name=3D"passw=
ord" placeholder=3D"Password" size=3D"30" type=3D&=
quot;password" /><br>
<br>
and a call to htmlfill with this:<br>
=C2=A0 =C2=A0formencode.htmlfill.render(\<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0form_content,<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0defaults=3Ddefaults,<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0errors=3Derrors,<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0auto_error_formatter=3Dcustom_for=
matter<br>
=C2=A0 =C2=A0)<br>
<br>
My output is essentially this:<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0Error Main -- rendered with default formatter<b=
r>
=C2=A0 =C2=A0 =C2=A0 =C2=A0email_address -- rendered with custom formatter=
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0password =C2=A0-- rendered with custom formatte=
r<br>
<br>
anyone have an idea to get the Error_Main section to render with the custom=
formatter along with the other fields =C2=A0(aside from specifying a custo=
m renderer in the field and passing in a dict )?<br>
---------------------------------------------------------------------------=
---<br>
Try before you buy =3D See our experts in action!<br>
The most comprehensive online learning library for Microsoft developers<br>
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,<br=
>
Metro Style Apps, more. Free future releases when you subscribe now!<br>
<a href=3D"http://p.sf.net/sfu/learndevnow-dev2" target=3D"_blank">http://p=
.sf.net/sfu/learndevnow-dev2</a><br>
_______________________________________________<br>
FormEncode-discuss mailing list<br>
<a href=3D"mailto:FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org" target=3D"_blan=
k">FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/formencode-discuss"=
target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/formencode-=
discuss</a><br>
</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>Christopher =
Lambacher<br><a href=3D"mailto:[email protected]" target=3D"_blank">ch=
[email protected]</a><br>
</div>
</blockquote></div><br></div></div><div>
<span style=3D"text-indent:0px;letter-spacing:normal;font-variant:normal;te=
xt-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:norm=
al;border-collapse:separate;text-transform:none;font-size:medium;white-spac=
e:normal;font-family:Helvetica;word-spacing:0px"><span style=3D"text-indent=
:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font=
-style:normal;font-weight:normal;line-height:normal;border-collapse:separat=
e;text-transform:none;font-size:medium;white-space:normal;font-family:Helve=
tica;word-spacing:0px"><div style=3D"word-wrap:break-word">
<span style=3D"text-indent:0px;letter-spacing:normal;font-variant:normal;te=
xt-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:norm=
al;border-collapse:separate;text-transform:none;font-size:medium;white-spac=
e:normal;font-family:Helvetica;word-spacing:0px"><div style=3D"word-wrap:br=
eak-word">
<span style=3D"text-indent:0px"><div style=3D"word-wrap:break-word"><span s=
tyle=3D"text-indent:0px"><div style=3D"word-wrap:break-word"><span style=3D=
"text-indent:0px"><div style=3D"word-wrap:break-word"><div><div>// Jonathan=
Vanasco</div>
<div><br></div><div>c. <a href=3D"tel:646.729.6436" value=3D"+16467296436" =
target=3D"_blank">646.729.6436</a> =C2=A0| =C2=A0<a href=3D"tel:415.501.981=
5" value=3D"+14155019815" target=3D"_blank">415.501.9815</a></div><div>e. <=
a href=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a>=
</div>
<div>w. <a href=3D"http://findmeon.com/user/jvanasco" target=3D"_blank">htt=
p://findmeon.com/user/jvanasco</a>=C2=A0</div><div>linkedin. <a href=3D"htt=
p://linkedin.com/in/jonathanvanasco" target=3D"_blank">http://linkedin.com/=
in/jonathanvanasco</a></div>
<div>blog. <a href=3D"http://destructuring.net" target=3D"_blank">http://de=
structuring.net</a></div></div></div></span></div></span></div></span></div=
></span></div></span></span>
</div>
<br></div></div></blockquote></div><br><br clear=3D"all"><div><br></div>-- =
<br>Christopher Lambacher<br><a href=3D"mailto:[email protected]">chri=
[email protected]</a><br>
--e0cb4efe34dc4d562404b9988a5d--
--===============7665262677042375534==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
--===============7665262677042375534==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
FormEncode-discuss mailing list
FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/formencode-discuss
--===============7665262677042375534==--