# table definition
db.define_table('vehicle',
                Field('manufacturer','string'),
                Field('name','string'),
                Field('vin','string',length=32,unique=True),
                Field('year','string'),
                Field('colour','string'),
                Field('comment','string'),
                Field('date','date',default=now),
                migrate='vehicle.table',format='%(manufacturer)s %(name)s 
%(year)s %(vin)s'
)

# present validator
db.vehicle.vin.requires=[IS_UPPER(), 
IS_NOT_IN_DB(db(db.vehicle.vin==request.vars.vin),db.vehicle.vin)]

# I have js function: validate_vin(VIN_NUMBER) that returns True or False

# If I had a form variable "vinOK" I could assign test result to it: 
jQuery("#vinOK").val(validate_vin(jQuery("#vehicle_vin").val()))

# then use the enhanced validator
# this is only hypothetical because the form has no variable "vinOK" but it 
would be desirable because I could use the functionality of the validator 
to show error in the form

db.vehicle.vin.requires=[IS_EXPR(('"True" == "%s"' % 
str(request.vars.vinOK)),error_message="VIN not good"),IS_UPPER(), 
IS_NOT_IN_DB(db(db.vehicle.vin==request.vars.vin),db.vehicle.vin)]

# A hidden field would be a solution to store the result of the js function 
but hidden fields don't seem to work in web2py for security reasons.( That 
is my understanding)
# Any solution would be OK as long as I can use validator's functionality 
to show error message. Perhaps I do not need the hidden variable at all. 
How do I pass VIN test result to the validator? Thanks a lot in advance.

-- 
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/d/optout.

Reply via email to