In your model:
response.files.append("http://www.pengoworks.com/workshop/jquery/lib/jquery.autocomplete.js")
response.files.append("http://www.pengoworks.com/workshop/jquery/lib/jquery.autocomplete.css")
def ajax_autocomplete(f,v):
items_url = URL(r=request,f="get_items")
wrapper = DIV()
inp = SQLFORM.widgets.string.widget(f,v)
scr1 = SCRIPT("jQuery('#%s').autocomplete('%s');" % (inp['_id'],items_url),_type="text/javascript")
wrapper.components.extend([inp,scr1])
return wrapper
db.define_table("widgets", Field("state",widget=ajax_autocomplete))
In your controller:
def index():
form = SQLFORM(db.widgets)
if form.accepts(request.vars,session):
response.flash = "New record added"
all = db().select(db.widgets.ALL)
return dict(form=form,all=all)
def get_items():
q = request.vars.q
if q:
states = ['Alabama','Alaska','American Samoa','Arizona','Arkansas','California','Colorado',
'Connecticut','Delaware','District of Columbia','Florida','Georgia','Guam','Hawaii',
'Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland',
'Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska',
'Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota',
'Northern Marianas Islands','Ohio','Oklahoma','Oregon','Pennsylvania','Puerto Rico',
'Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia',
'Virgin Islands','Washington','West Virginia','Wisconsin','Wyoming']
match = '\n'.join([s for s in states if q.lower() in s.lower()])
return match
return ''
Comments (12)
0
sophie 15 years ago
0
mrfreeze 15 years ago
0
sophie 15 years ago
0
mrfreeze 15 years ago
0
sophie 15 years ago
0
mrfreeze 15 years ago
0
sophie 15 years ago
0
sophie 15 years ago
0
mrfreeze 15 years ago
0
mrfreeze 15 years ago
0
sophie 15 years ago
0
mrfreeze 15 years ago