Here is a little better with a title in the modal and some comments of
explanation
# create a model
db.define_table('organization',Field('name',notnull=True,unique=True),format='%
(name)s')
db.define_table('person',Field('name'),Field('organization',db.organization))
# create link that open a modal window and calls
# add_organization via ajax using web2py ajax trapping
# forms will be processed and stay in the modal window if errors
db.person.organization.comment = \
SPAN(A('add',_class='thickbox',
_title='Add a new organizaiton',
_href='#TB_inline?
height=100&width=600&inlineId=modal_content'),
DIV(LOAD('default','add_organization',ajax=True),
_id='modal_content',_class='hidden'))
# load required ajax libraries
response.files.append('http://jquery.com/demo/thickbox/thickbox-code/
thickbox.js')
response.files.append('http://jquery.com/demo/thickbox/thickbox-code/
thickbox.css')
# this is your main action (nothing special here)
def index():
return dict(form=crud.create(db.person,request.args(0)))
# this is the ajax callback
def add_organization():
def update_select(form):
# this function updates the content of the select dropdown
(web2py trick)
# and closes the modal
organizations =
db(db.organization.id>0).select(orderby=db.organization.name)
options = TAG['']
(*[OPTION(o.name,_value=o.id,_selected=form.vars.id==o.id) for o in
organizations])
response.headers['web2py-component-command'] =
"jQuery('#person_organization').html('%s');jQuery('#TB_closeWindowButton').click()"
% options
return crud.create(db.organization,onaccept=update_select)
On Feb 19, 11:52 pm, mdipierro <[email protected]> wrote:
> On Feb 19, 8:54 pm, Jose <[email protected]> wrote:
>
> > how to this [1] with webpy?
>
> > [1]http://www.vimeo.com/9526668
>
> Here is complete code:
>
> 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 = \
> SPAN(A('add',_class='thickbox',
> _href="#TB_inline?
> height=200&width=600&inlineId=modal_content"),
> DIV(LOAD('default','add_organization',ajax=True),
> _id='modal_content',_class='hidden'))
>
> response.files.append('http://jquery.com/demo/thickbox/thickbox-code/
> thickbox.js')
> response.files.append('http://jquery.com/demo/thickbox/thickbox-code/
> thickbox.css')
>
> def index():
> return dict(form=crud.create(db.person,request.args(0)))
>
> def add_organization():
> def update_select(form):
> organizations =
> db(db.organization.id>0).select(orderby=db.organization.name)
> options = TAG['']
> (*[OPTION(o.name,_value=o.id,_selected=form.vars.id==o.id) for o in
> organizations])
> response.headers['web2py-component-command'] =
> "jQuery('#person_organization').html('%s');jQuery('#TB_closeWindowButton').click()"
> % options
> return crud.create(db.organization,onaccept=update_select)
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.