You can't really pre-populate the field because you don't know the cpu value until after the user selects the sku. So, you'll have to do this with JS/jQuery and Ajax on the client side. Use jQuery to detect the sku selection, and when detected, send an Ajax request to web2py to have it look up the associated cpu. Check out http://web2py.com/book/default/chapter/10#The-ajax-Function for some ideas.
Anthony On Thursday, December 15, 2011 7:08:04 PM UTC-5, Adi wrote: > > I'm still trying to resolve my problem, and desperately need someone's > help :) > > When I try to add a new sku to a purchase order, I would like to > prepopulate "CPU" field with the value from db.sku.cpu (determined by a > dropdown). > > http://127.0.0.1:8000/test/default/list_purchase_orders/purchase_order/po_sku.po_id/1/new/po_sku > > Is it possible to do this through smartgrid, and how would I do it? Bellow > is a short version of my code for this... I'm stuck... :( > > #db.py > db.define_table('sku', > Field('sku_number', 'string', label=T('SKU #')), > Field('description', 'string', label=T('Description')), > Field('cpu', 'double'), > Field('note', 'text'), > format='%(sku_number)s - %(description)s', > ) > > db.define_table('purchase_order', > Field('po_number', 'string'), > ) > > db.define_table('po_sku', > Field('sku_id', db.sku, label=T('SKU #')), > Field('po_id', db.purchase_order, label=T('Purchase Order > #')), > Field('qty', 'integer'), > Field('cpu', 'double'), > ) > > # default.py > def list_purchase_orders(): > db.purchase_order.id.readable = False > > db.purchase_order['_plural'] = 'Purchase Orders' > > grid=SQLFORM.smartgrid(db.purchase_order, details=True, > links_in_grid=True, > maxtextlengths={'purchase_order.po_number':15}, > maxtextlength=20, > paginate=20, > csv=False, > ui='jquery-ui', > user_signature=False, oncreate = auth.archive, > onupdate=auth.archive) > return dict(grid=grid) > >