Aw crap! and here is little me thinking I know how to use web2py. This one requires some painfully detailed walk-through. Am I the only one?.
On 20 feb, 02:39, mdipierro <mdipie...@cs.depaul.edu> wrote: > En even better solution. > > Drop this code in your model somewhere: > > def ajax_create(field, > value='create', > title='Add a new organizaiton', > height=100, width=600): > if not field.type.startswith('reference'): > raise SyntaxError, "can only be used with a reference field" > if not hasattr(field.requires,'options'): > raise SyntaxError, "cannot determine options from field > validator" > key = str(field).replace('.','_') > if request.get_vars._ajax_add==str(field): > def update_select(form): > options = TAG[''] > (*[OPTION(v,_value=k,_selected=str(form.vars.id)==str(k)) \ > for (k,v) in > field.requires.options()]) > command = "jQuery('# > %s').html('%s');jQuery('#TB_closeWindowButton').click()" \ > % (key,options.xml().replace("'","\'")) > response.headers['web2py-component-command'] = command > table = field._db[field.type[10:]] > raise > HTTP(200,crud.create(table,onaccept=update_select).xml(),**response.headers) > response.files.append('http://jquery.com/demo/thickbox/thickbox- > code/thickbox.js') > response.files.append('http://jquery.com/demo/thickbox/thickbox- > code/thickbox.css') > return TAG['']( > A(value,_class='thickbox',_title=title, > _href='#TB_inline?height=%s&width=%s&inlineId=TB_%s' % > (height,width,key)), > DIV(LOAD(request.controller,request.action,args=request.args, > vars=dict(_ajax_add=field),ajax=True),_id='TB_%s' % > key,_class='hidden')) > > Then you just do: > > db.define_table('organization',Field('name',notnull=True,unique=True),format='% > (name)s') > db.define_table('person',Field('name'),Field('organization',db.organization)) > > db.person.organization.comment = ajax_create(db.person.organization, > title='Add an Org.') > > def index(): > return dict(form=crud.create(db.person,request.args(0))) > > Will work with any table/field that you already have. > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.