Is there a way to close the autocomplete field when the option get clicked?
On Thu, Feb 18, 2010 at 11:40 AM, ecall <edouard.call...@gmail.com> wrote: > The trace come from a fresh (web2py 1.75.3) install. I just add the > magic. > > welcome/controllers/default.py : > ------------------------------ > ### assume this action in controller default.py > def launch(): > db.photon_torpedo.target.represent=lambda target: target.name > return dict(new_torpedo=crud.create(db.photon_torpedo), > launched_torpedos=db().select(db.photon_torpedo.ALL)) > > welcome/models/db.py : > -------------------- > ### assume this model > db.define_table('target',Field('name')) > if not db(db.target.id>0).count(): > db.target.insert(name="Klingon") > db.target.insert(name="Romulans") > db.target.insert(name="Borg") > db.target.insert(name="Borg2") > db.define_table('photon_torpedo',Field('target',db.target)) > > from gluon.sqlhtml import AutocompleteWidget > db.photon_torpedo.target.widget=AutocompleteWidget(request,db.target.name, > db.target.id) > > > > On 18 fév, 15:29, mdipierro <mdipie...@cs.depaul.edu> wrote: > > Can you post your code? Are you doing autocomplete for a reference > > field? If so, do you have the validator? > > > > On Feb 18, 2:19 am, ecall <edouard.call...@gmail.com> wrote: > > > > > I use your photon_torpedo/target sample in "welcome" application. > > > > > The request > > > ishttp://127.0.0.1:8080/welcome/default/launch(GAE<http://127.0.0.1:8080/welcome/default/launch%28GAE> > > > 1.3.1) > > > > > ERROR 2010-02-18 09:04:36,200 restricted.py:53] In FILE: C: > > > \Python25\eclipse\workspace\web2py_1.75.3\applications\welcome/ > > > controllers/default.py > > > > > Traceback (most recent call last): > > > File "C:\Python25\eclipse\workspace\web2py_1.75.3\gluon > > > \restricted.py", line 173, in restricted > > > exec ccode in environment > > > File "C:\Python25\eclipse\workspace\web2py_1.75.3\applications > > > \welcome/controllers/default.py:launch", line 62, in <module> > > > File "C:\Python25\eclipse\workspace\web2py_1.75.3\gluon\globals.py", > > > line 96, in <lambda> > > > self._caller = lambda f: f() > > > File "C:\Python25\eclipse\workspace\web2py_1.75.3\applications > > > \welcome/controllers/default.py:launch", line 59, in launch > > > File "C:\Python25\eclipse\workspace\web2py_1.75.3\gluon\tools.py", > > > line 2395, in create > > > deletable=False, > > > File "C:\Python25\eclipse\workspace\web2py_1.75.3\gluon\tools.py", > > > line 2333, in update > > > upload=self.settings.download_url, > > > File "C:\Python25\eclipse\workspace\web2py_1.75.3\gluon\sqlhtml.py", > > > line 675, in __init__ > > > inp = field.widget(field, default) > > > File "C:\Python25\eclipse\workspace\web2py_1.75.3\gluon\sqlhtml.py", > > > line 434, in __call__ > > > record = > > > self.db(self.fields[1]==value).select(self.fields[0]).first() > > > File "C:\Python25\eclipse\workspace\web2py_1.75.3\gluon\contrib > > > \gql.py", line 673, in select > > > (items, tablename, fields) = self._select(*fields, **attributes) > > > File "C:\Python25\eclipse\workspace\web2py_1.75.3\gluon\contrib > > > \gql.py", line 636, in _select > > > item = self._db[tablename]._tableobj.get_by_id(filter.right) > > > File "C:\Python25\eclipse\workspace\google_appengine_1.3.1\google > > > \appengine\ext\db\__init__.py", line 1010, in get_by_id > > > return get(keys[0], rpc=rpc) > > > File "C:\Python25\eclipse\workspace\google_appengine_1.3.1\google > > > \appengine\ext\db\__init__.py", line 1203, in get > > > keys, multiple = datastore.NormalizeAndTypeCheckKeys(keys) > > > File "C:\Python25\eclipse\workspace\google_appengine_1.3.1\google > > > \appengine\api\datastore.py", line 141, in NormalizeAndTypeCheckKeys > > > keys = [_GetCompleteKeyOrError(key) for key in keys] > > > File "C:\Python25\eclipse\workspace\google_appengine_1.3.1\google > > > \appengine\api\datastore.py", line 2354, in _GetCompleteKeyOrError > > > raise datastore_errors.BadKeyError('Key %r is not complete.' % > > > key) > > > BadKeyError: Key datastore_types.Key.from_path(u'target', 0L, > > > _app=u'web2py') is not complete. > > > > > INFO 2010-02-18 09:04:36,200 gaehandler.py:55] **** Request: > > > 109.00ms/109.00ms (real time/cpu time) > > > INFO 2010-02-18 09:04:36,246 dev_appserver.py:3246] "GET /welcome/ > > > default/launch HTTP/1.1" 200 - > > > > > Says 200, but the browser send this: > > > Status: 500 INTERNAL SERVER ERROR > > > Content-Type: text/html; charset=UTF-8 > > > web2py_error: ticket welcome/ > > > 127.0.0.1.2010-02-18.08-16-43.e1b0f638-417c-4108-a75b-f809cb1de3ec > > > Content-Length: 841 > > > > > Thx > > > > > On 18 fév, 00:26, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > > I have never seen this error. Can you show the relavant code and the > > > > complete traceback? > > > > > > On Feb 17, 3:58 pm, ecall <edouard.call...@gmail.com> wrote: > > > > > > > Thanks for this nice feature. > > > > > > > How can I make it run with ./dev_appserver.py (development for > gae)? > > > > > > > So far, I have this: > > > > > File > "......../workspace/google_appengine/src/google/appengine/api/ > > > > > datastore.py", line 2172, in _GetCompleteKeyOrError > > > > > raise datastore_errors.BadKeyError('Key %r is not complete.' % > > > > > key) > > > > > BadKeyError: Key datastore_types.Key.from_path(u'target', 0L, > > > > > _app_id_namespace=u'web2py') is not complete. > > > > > > > Regards, > > > > > Edouard > > > > > > > On 6 fév, 21:30, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > > > > People say there is some magic in web2py. > > > > > > Here is some real magic now in trunk that I am sure you have > never > > > > > > seen. > > > > > > > > Caveats: > > > > > > 0) requires latest trunk (bzr 1603, hg 175:e42b559254f6) > > > > > > 1) this is an experiment, not sure it is a good idea > > > > > > 2) this is the first function in web2py that REQUIRES jQuery > > > > > > 3) works but I am not yet convinced it should stay there > > > > > > 4) even if it stays, I am sure the API should stay > > > > > > > > Example: > > > > > > > > ### assume this model > > > > > > db.define_table('target',Field('name')) > > > > > > if not db(db.target.id>0).count(): > > > > > > db.target.insert(name="Klingon") > > > > > > db.target.insert(name="Romulans") > > > > > > db.target.insert(name="Borg") > > > > > > db.target.insert(name="Borg2") > > > > > > db.define_table('photon_torpedo',Field('target',db.target)) > > > > > > > > ### assume this action in controller default.py > > > > > > def launch(): > > > > > > db.photon_torpedo.target.represent=lambda target: > target.name > > > > > > return dict(new_torpedo=crud.create(db.photon_torpedo), > > > > > > > launched_torpedos=db().select(db.photon_torpedo.ALL)) > > > > > > > > So far nothing new. > > > > > > > > Now append to the model or insert at top of controller the > following: > > > > > > > > from gluon.sqlhtml importAutocompleteWidget > > > > > > db.photon_torpedo.target.widget=AutocompleteWidget(request, > db.target.name,db.target.id) > > > > > > > > No need to define any callback action (there is no callback > action!) > > > > > > No plugin required (perhaps some optional css to style). > > > > > > No js coding required. > > > > > > Applies to existing apps, including those that use custom forms. > > > > > > > > Let's see who can figure out how it works! > > > > > > > > Massimo > > > > > > -- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To post to this group, send email to web...@googlegroups.com. > To unsubscribe from this group, send email to > web2py+unsubscr...@googlegroups.com<web2py%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/web2py?hl=en. > > -- Linux User #387870 .........____ .... _/_õ|__| ..º[ .-.___.-._| . . . . .__( o)__( o).:_______ -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.