What is form.notnull?

56 views
Skip to first unread message

John Sullivan

unread,
May 9, 2012, 11:29:49 PM5/9/12
to web.py
Hello,

I have searched through much of the mailing list, all of the
documentation I could find, Google, and tried the freenode channel
(which seems to be dead). I can not find out what the purpose is of
having form.notnull inside of the form objects' constructors. The only
description of it that I could find is at webpy.org/form#inputfeatures
but it wasn't very clear:

form.textbox("firstname",
form.notnull, #put validators first followed by optional
attributes
class_="textEntry", #gives a class name to the text box -- note
the underscore
pre="pre", #directly before the text box
post="post", #directly after the text box
description="please enter your name", #describes field, defaults
to form name ("firstname")
value="bob", #default value
id="nameid", #specify the id
)

Could anyone tell me what the purpose of form.notnull is? Or point me
to some literature I missed that explains it to me?

Scott Gelin

unread,
May 10, 2012, 8:36:13 AM5/10/12
to we...@googlegroups.com
Hey John,
form.notnull is an example of a built-in validator that the web.py Form module uses to verify the contents of the form when you form form.validates().  Form.notnull means the value inside that particular input element must be not null in order to validate properly.

You don't need to use form.notnull, but its convenient - and there can be more than one validator.  See this example for reference:

    form.Textbox("bax", 
        form.notnull,
        form.regexp('\d+', 'Must be a digit'),
        form.Validator('Must be more than 5', lambda x:int(x)>5))

That has 3 different validators notnull, a regex and a length check.  Validators come first in the form elements argument list, then optional arguments like pre, post, class, etc. follow.

--
You received this message because you are subscribed to the Google Groups "web.py" group.
To post to this group, send email to we...@googlegroups.com.
To unsubscribe from this group, send email to webpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webpy?hl=en.


John Sullivan

unread,
May 10, 2012, 2:27:27 PM5/10/12
to we...@googlegroups.com
Thank you very much! I was under the impression that it was marking the end of the argument list which was confusing me to no end.

Have a great day,
John Sullivan
To unsubscribe from this group, send email to webpy+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages