I have been using the autocomplete widget which makes is really convenient.
However, there are times where I would like to customise what is shown in
the SELECT say with a custom expression rather than being limited to each
OPTION being the value of the field in the row.
It appears that the autocomplete widget does not accept a lambda in place
of a field. However, I guess one approach would be to define a virtual
field which could then be listed on the option. However, in my usage
scenario, I am looking for a way to display full addresses in the SELECT
when the user starts to enter a fragment of the postcode. Given that
postcodes are expected at the end of the address rather than at the start,
the autocomplete will not match that. Also, I am not sure if it would be a
good idea to do this with a virtual field over a large addresses dataset.
So, as an alternative, I have been toying with a workaround in which I try
to override the autocomplete AJAX call. Say given a function/url /address,
I have the following in my controller:
def address():
if request.vars._autocomplete_address_postcode: return SELECT([OPTION("%s
%s" % (r.addr, r.postcode) for r in db(db.address.postcode.like('%s%%' %request
.vars._autocomplete_address_postcode)).select()])
This however does not appear to run and I still get the default
autocomplete behaviour.
Any ideas?
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.