Paul,
IMO, pulling up all the entries defeats the purpose of an autocomplete (not
to mention if you have more than just a few options-it'll prevent a
scrolling nightmare.)
The way that I've addressed this problem in the past is by setting the
Autocomplete matchSubset option to true/1.
On the backend, I design my queries to pull out matches the start off
exactly the way the user typed the phrase in first and then return results
where the string is anywhere else in the string.
So, if the user was searching for Cities in Ohio and typed in the letters
"Fi", the results in the drop down box would look like:
Findley
Blissfield
Brookfield
Canfield
Chatfield
Deerfield
Defiance
East Springfield
Farifield
Greenfield
This puts the most logical choices at top, but perimeter options will still
show up.
The basic SQL idea is to union 2 queries together, where the first query
does a LIKE 'string%' and the second query does a LIKE '%string%'-and
excludes all matches from the first query. You'll also want to add a alias
column that assigns a static value to each query, that way you can properly
order by the queries.
Example:
select
cityId, name, 1 as exactMatch
from
city
where
name like '#url.q#%'
union
select
cityId, name, 0 as exactMatch
from
city
where
name like '%#url.q#%'
and
cityId not in (
select
cityId
from
city
where
name like '#url.q#%'
)
order by
exactMatch desc, name asc
Hope this help!
-Dan
_____
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Paul
Sent: Wednesday, March 21, 2007 12:11 PM
To: 'jQuery Discussion.'
Subject: [jQuery] modifying autocomplete behavior
I'm using the pengoworks autocomplete plugin
(http://www.pengoworks.com/workshop/jquery/autocomplete.htm) and would like
to make an enhancement. Unfortunately I'm not sure where to begin.
I'm using the autocomplete function within an intranet application. When
the staff knows which product name they wish to select it works well, but
there are a few times when an infrequently-used product needs to be
selected, and they may not know the first few characters to populate the
list.
I would like to modify the plugin so that pressing "escape" returns the
autocomplete result populated with all possible records which users can
scroll through. Do any of you know what I might need to do to get started?
-Paul
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/