Multiple AutoComplete options, ugly but works.
Posted: novembro 21st, 2006 | Author: coredump | Filed under: Linux e Open Source, Programação | Tags: javascript, turbogearsSo, I was trying to make the Turbogears AutoComplete Widget work like the address field from gmail or hotmail. Basically to continue searching after a comma to add values. My javascript is not that good and I felt a little bad on messing with the default widgets, so I did something on the search controller to mimic this behavior. This is the complete controller I use with the Widget:
def complete(self, tagname):
tags = ['linux', 'security', 'love', 'politics', 'sex', 'religion',
'esports', 'programming', 'scifi', 'theories', 'spaced tag']old_tagname = None
if ‘,’ in tagname:
new_tagname = tagname.replace(‘ ‘, ”).split(‘,’)
tagname = new_tagname.pop().strip()
old_tagname = ‘, ‘.join(new_tagname)if tagname == ”:
return dict(tag = [])reslist = []
for tag in tags:
if tag.startswith(tagname):
if old_tagname:
tag = old_tagname + ‘, ‘ + tag
reslist.append(tag)return dict(tag = reslist)
@expose()
def default(self, *w, **kw):
raise redirect(“/”)
Yes, it’s kinda ugly but it works. In Brazil this is called gambiarra. I’ll elaborate a little more after, there’re too many variables and I’m sure I can make something more compact. Right now I just need this working
cya.Technorati Tags: turbogears, autocomplete, widgets, hacking
Posts relacionados:
- CherryPy Session e message queue Tem vezes que eu faço umas coisas que eu acho...
- Kindness of Strangers Tá bom… Vocês ficaram com dó e não me falaram...
- Turbogears Validators, Widgets and i18n (or how I got it to work) <Originally posted on the turbogears mail list> So, for the...
- Turbogears, Mysql and UTF. Advice Needed! So, I have this little problem… For design reasons, I...
- Cavando! Release de protótipo E então. Nas últimas semanas estive tendo cravings de programação...

Leave a Reply