Come up with this solution: db.py db.define_table('t', Field('a', type='integer'), Field('b', type='integer') )
default.py def index(): grid = SQLFORM.smartgrid(db.t) return locals() def do_this(): # ... return {'one':request.vars.b, 'two':request.vars.a} index.html <script> $(document).ready(function(){ $("#t_a").change(function(){ $.ajax({url:"{{=URL('default','do_this.json')}}",data:{'a':$("#t_a").val(),'b':$("#t_b").val()}, dataType: 'json',success:function(result){ $("#t_b").val(result.two); }}); }); }); </script> {{=grid}} In controller function "do_this" I can perform all the database lookup I need, based on the values passed by the ajax call. On Thursday, October 4, 2012 9:49:27 AM UTC+9, alex wrote: > > > I have a SQLFORM.grid. > When the user updates field 'a' in the grid, before submitting the form, > field 'b' should represent a calculation based on value of 'a'. > For instance b=a+1 > > db.py > db.define_table('t', > Field('a', type='integer'), > Field('b', type='integer') > ) > > default.py > def index(): > grid = SQLFORM.smartgrid(db.t) > return locals() > > index.html > {{extend 'layout.html'}} > {{=grid}} > > Someone can help? > --