How do I expose validators as JSON?

I am not using web2py views in any capacity. Instead I am using AngularJS.

So with web2py I am exposing my models RESTfully as JSON, and then
consuming them with AngularJS.

To reduce double-typing, how do I send field validators such as
`IS_EMAIL` as JSON?

# Model
db.define_table(
    'foo',
    Field('email', requires=IS_EMAIL())
)

# Controller
@service.json
def foo_form():
    return dict(my_foo_form=crud.create(db.foo))

# Output I want
{ 'my_foo_form': { 'type': 'form', 'fields' { 'email',
'validator:IS_EMAIL'}, 'csrf': <uid> } }

----

With this I can then write the equivalent functions in JavaScript and
attach them to their corresponding fields.

How do I do this with web2py?

Thanks for all suggestions,

Alec Taylor

-- 



Reply via email to