Re: empty passed to All -> 'Please Enter a Value'

Ian Bicking <[email protected]> Fri, 13 Jun 2008 17:56:47 -0500
Newsgroups gmane.comp.python.formencode
Message-ID <[email protected]>
Kevin Mateo Lim wrote:
> Hey Guys,
> 
> I'm new to FormEncode, and I'm seeing some behavior that I don't expect.
> 
> I'm using the compound validator all to check to see if my username is
> unique and plaintext
> 
>     username = All(UniqueUsername(),
> validators.PlainText(not_empty=True, messages={'empty':"Yeah, go ahead
> and enter a user name"}))
> 
> when the field is submitted empty, the error message that that prints
> is always :
> 'Please enter a value'
> 
> which isn't the best user experience, imho.
> 
> the thing is, neither my custom UniqueUsername nor PlainText (with the
> above messages dict) should output that message.
> 
> When I take both validators out of the All() compound, they both print
> "Yeah, go ahead and enter a user name."
> 
> But once they're in there, it reverts back to the boring one.
> 
> Am I doing something wrong?

Hrm... it seems All subclasses FancyValidator, which has an empty check, 
so All(..., messages=dict(empty='yeah yeah')) would do it.

This isn't ideal.  I think maybe Mark was thinking of implementing a 
better All though (All also has the ordering all wrong)...?  Might be 
better to fix it there.

-- 
Ian Bicking : [email protected] : http://blog.ianbicking.org

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php