+1

would a 'json:reference mytable' field type similar to 'list:reference 
mytable' or perhaps a format=lambda row: row.json() be possible? 

-Bill



On Tuesday, January 15, 2013 6:14:40 PM UTC-6, Derek wrote:
>
> That would be cool, perhaps you could add a class to the fields and key 
> off the classes. Or, have the validation function append error messages to 
> a list and return that as json?
>
> On Tuesday, January 15, 2013 10:03:06 AM UTC-7, Alec Taylor wrote:
>>
>> 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