Is there a comprehensive guide to doing validators? The website just has a few examples of magic incantations :)

On 06/04/2013 02:06 PM, daniel crisan wrote:
'Solve it,

Add the following line before "register_form =...."
      v = [form.Validator("Check more than 3", lambda x: len(x.check)>3)]
Then modify line "register_form= ....."
      register_form = form.Form(validators=v, *args)
to add the validator.

Then modify line: "if not f.validates():"
      if not f.validates(web.input(check=[])):
to pass the submited data and validate it.


Hope this helps. I was searching the net for a "quick" solution but could not find one.

On Tuesday, June 4, 2013 7:16:58 PM UTC+3, daniel crisan wrote:

    Hello,

    I need to validate a form only if X or more checkboxes were
    checked and I cannot find out how. Bellow is the simple code which
    needs the validator (there are 5 checkboxes - same name - and the
    form should validate only if 3 or more were selected). Can you
    please point me to the right direction?

    import web
    from web import form

    render = web.template.render('templates/')

    urls = ('/', 'index')
    app = web.application(urls, globals())

    args = ()
    for i in range(0, 5):
        args = args + ( form.Checkbox('check', value=str(i) ), )
    args = args + (form.Button("submit", type="submit",
    description="Submit"),)

    register_form = form.Form(*args)

    class index:
        def GET(self):
            # do $:f.render() in the template
            f = register_form()
            return render.register(f)

        def POST(self):
            f = register_form()
            if not f.validates():
                return render.register(f)
            else:
                pdata=web.input(check=[])
                print pdata
    if __name__=="__main__":
        web.internalerror = web.debugerror
        app.run()

--
You received this message because you are subscribed to the Google Groups "web.py" group. To unsubscribe from this group and stop receiving emails from it, send an email to webpy+unsubscr...@googlegroups.com.
To post to this group, send email to webpy@googlegroups.com.
Visit this group at http://groups.google.com/group/webpy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to webpy+unsubscr...@googlegroups.com.
To post to this group, send email to webpy@googlegroups.com.
Visit this group at http://groups.google.com/group/webpy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to