db.service_order.so_company.widget = suggest_widget(db.company.company_name, id_field=db.company.id, limitby=(0, 10), min_length=1)
"""Below Works Just fine"""
db.service_order.so_location.widget = lazy_options_widget( 'service_order_so_company__selected', 'service_order_so_company__unselected', lambda so_company_id: (db.g_location.company == so_company_id), request.vars.so_company, orderby=db.g_location.id, field=db.service_order.so_location, )"""This Widget is not working, It should determine its select options from the above widgets field"""
db.service_order.so_lease.widget = lazy_options_widget( 'service_order_so_location__selected', 'service_order_so_location__unselected', lambda so_location_id: (db.lease.lease_location == so_location_id), request.vars.so_lease, orderby=db.lease.id, field=db.service_order.so_lease, )
def index(): form = SQLFORM(db.product) if form.accepts(request.vars, session): session.flash = 'submitted %s' % form.vars redirect(URL('index')) return dict(form=form, categories=SQLTABLE(db().select(db.category.ALL)), colors=SQLTABLE(db(db.color.id > 0)(db.color.category == db.category.id
from plugin_lazy_options_widget import lazy_options_widgetfrom plugin_suggest_widget import suggest_widget
db = DAL('sqlite:memory:')db.define_table('category', Field('name'))db.define_table('color', Field('category', db.category), Field('name'))db.define_table('hue', Field('color', db.color), Field('name'))db.define_table('product', Field('category', db.category, comment='<- type "A" or "B"'), Field('color', db.color, comment='<- select category first'), Field('hue', db.hue, comment='<- select color first'),)
db.category.bulk_insert([{'name':'A'}, {'name':'B'}])
for category in db(db.category.id > 0).select(): _id = category.id if category.name == 'A': db.color.bulk_insert([{'category': _id, 'name':'red'}, {'category': _id, 'name':'blue'}]) elif category.name == 'B': db.color.bulk_insert([{'category': _id, 'name':'green'}])for color in db(db.color.id > 0).select(): _id = color.id if color.name == 'red': db.hue.bulk_insert([{'color': _id, 'name' : 'shiny'},{'color': _id, 'name': 'dull'}]) elif color.name == 'blue': db.hue.bulk_insert([{'color': _id, 'name' : 'glossy'},{'color': _id, 'name': 'dark'}]) elif color.name == 'green': db.hue.bulk_insert([{'color': _id, 'name' : 'opaque'},{'color': _id, 'name': 'light'}])
db.product.category.widget = suggest_widget(db.category.name, id_field=db.category.id, limitby=(0, 10), min_length=1)
################################ The core ####################################### The lazy_options_widget receives js events# called "product_category__selected" and "product_category__unselected"# which will be triggered by the above suggest_widget.]# You can also pass user_signature and hmac_key arguments for authorization in ajaxdb.product.color.widget = lazy_options_widget( 'product_category__selected', 'product_category__unselected', lambda category_id: (db.color.category == category_id), request.vars.category, orderby=db.color.id, # If you want to process ajax requests at the time of the object construction (not at the form rendered), # specify your target field in the following: field=db.product.color, )################################################################################db.product.hue.widget = lazy_options_widget( 'product_color__selected', 'product_color__unselected', lambda color_id: (db.hue.color == color_id), request.vars.color, orderby=db.hue.id, # If you want to process ajax requests at the time of the object construction (not at the form rendered), # specify your target field in the following: field=db.product.hue, )
def lookup():response.view = 'generic.json'query = request.vars.querydata = db(db.tablenamehere.fieldnamehere == query).select() or "none"return data.as_dict()
<script>var selectList = $("#IDOFYOURFIELD");
$('#TABLE_FIELD__display').change(function(){ value = $("#TABLE_FIELD__hidden").val(); $.getJSON("/app/defualt/lookup/",{ query: value }, function(response){ var responseList=""; $.each(response, function(index, item) { }); leaseList.html(responseList); });});
</script>