I thought some code might help. Here's the class that creates the LOAD 
helper to hold a form field widget:

class AjaxSelect:

    def __init__(self, field, value, linktable):
        self.field = field
        self.value = value
        self.linktable = linktable

    def widget(self):
        # initialize LOAD helper
        environment = {
            'request': current.request,
            'response': current.response}
        LOAD = LoadFactory(environment)

        #get field and tablenames for element id's
        fieldset = str(self.field).split('.')
        tablename = fieldset[0]
        fieldname = fieldset[1]

        loadname = '%s_%s_loader' %(tablename, fieldname)

        #create component wrapper with ajax loading helper
        wrapper = LOAD('plugin_ajaxselect', 'set_widget.load',
            args=[tablename, fieldname, self.value, self.linktable, 
loadname], ajax=True, target=loadname)

        return wrapper



And here's the controller that actually builds the widget:

table = request.args[0]
    field = request.args[1]
    value = request.args[2]
    linktable = request.args[3]
    loadname = request.args[4]

    the_table = db[table]
    the_field = the_table[field]
    the_linktable = db[linktable]

    w = OptionsWidget.widget(the_field, value)

    #create button to refresh component
    bid = table + '_' + field + '_refresher'
    comp_url = URL('plugin_ajaxselect', 'set_widget.load', args=[table, 
field, value, linktable, loadname])
    button = A('refresh', _href=comp_url, cid=request.cid)

    return dict(widget = w, button = button) 

Reply via email to