If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

Add the widget to your model:

def inplace_edit(f,v):
    wrapper = DIV()
    inp = SQLFORM.widgets.string.widget(f,v)
    lbl = SPAN(inp['_value'],_id='inplace_edit_'+inp['_id'],_style="cursor:pointer;")
    scr1 = "jQuery('#%s').hide();" % inp['_id']
    scr2 = "jQuery('#%s').bind('dblclick',function(e){ jQuery(this).hide();jQuery('#%s').show().focus();});" % \
    scr3 = "jQuery('#%s').bind('blur',function(e){ jQuery(this).hide();jQuery('#%s').show().text(jQuery(this).val());});" % \
    jqscr = SCRIPT(scr1,scr2,scr3,_type="text/javascript")
    return wrapper

Apply the widget to a field:

db.define_table("test",Field('edit',default='Double Click to edit',widget=inplace_edit))

Test it in your controller:

def index():
    form = SQLFORM(db.test)    
    if form.accepts(request.vars,session):
        response.flash = "Got it"
    all = db().select(db.test.ALL)
    return dict(form=form,all=all)

In-Place Edit Normal

In-Place Edit Editing

Demo application (right click/Save As): Download

Related slices

Comments (0)

Hosting graciously provided by:
Python Anywhere