[web2py] Validating list:string fields

2014-01-08 Thread curly
Hello,

I'm trying to validate a list:string field with is_alphanumeric and 
is_length - trying to ensure that names are no longer than 6 alphanumeric 
characters in length. (I'm running web2py 2.8.1 in ubuntu 12.04)

view:
liSample name *: {{=form.custom.widget.sample_name}}/li

controller:
form = SQLFORM(db.register,fields=[..,'sample_name',...])

if form.validate(onvalidation=validate_sample_name):
form.vars.id = db.register.insert(**dict(form.vars))
response.flash = 'Reg saved.'
redirect(URL('samples', 'default', 'index'))
elif form.errors:
response.flash = 'form has errors'  
return dict(form=form)

model:
db.define_table(
register,
.
Field('sample_name','list:string'),
)

def validate_sample_name(form):
for sample in form.vars.sample_name:
out,ers = IS_ALPHANUMERIC()(sample) and 
IS_LENGTH(maxsize=6)('sample')
if ers:
form.errors.sample_name = ers


The above does check for alphanumeric characters but doesn't seem to check 
for the length of each sample name.

Am I doing something wrong?

Many thanks.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Customization of the SQLFORM in html

2013-12-13 Thread curly
Hello!

I'm new to web2py and have just started running web2py 2.8.1 in ubuntu 
12.04.

I am trying to customize the style of SQLFORM in web2py views. Tried to do 
this using SQLFORM in HTML. What I have is:-

model:
db.define_table(
register,
Field('pi_id',db.pi),
Field('name',requires=[IS_NOT_EMPTY(), IS_ALPHANUMERIC()]),
Field('grp_name'),
Field('req_date','date', requires = IS_DATE(format=('%d-%m-%Y'))),
Field('email',requires=[IS_EMAIL()]))
db.register.grp_name.widget = SQLFORM.widgets.autocomplete(
 request, db.pi.name, limitby=(0,10), min_length=1)

controller:
def display_your_form():
form = 
SQLFORM(db.register,fields=['name','grp_name','req_date','email'])
if form.process(session=None,formname=test).accepted:
response.flash = 'Reg saved.'
redirect(URL('samples', 'default', 'index'))
elif form.errors:
response.flash = 'form has errors'  
return dict()

view:
{{extend 'layout.html'}}
form action=# enctype=multipart/form-data method=post
ul
  liYour name is input name=name //li
  liYour group is input name=grp_name //li
  liYour request date is input name=req_date //li
  liYour email is input name=email //li
/ul
  input type=submit /
  input type=hidden name=_formname value=test /
/form


Unfortunately, I now no longer get error messages for fields that are left 
empty, a date app to help insert a date, and the autocomplete doesn't work 
(all of these worked fine with the default view of SQLFORM). Am I missing 
something obvious?

Would custom forms be a better way of doing this?

Many thanks.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.