Autocomplete field
Peter Brigham MD
pmbrig at gmail.com
Thu Oct 29 18:33:53 EDT 2009
On Oct 28, 2009, at 12:53 PM, capellan wrote:
>
> Hi all,
>
> Visit the webpage:
> http://www.capellan2000.000space.com/test05.html
> and download the stack:
> http://capellan2000.000space.com/autocomplete_names.zip
>
> I am looking for ideas to make better the code of
> these autocomplete fields.
I modified your code to include filtering the displayed list. Works
like a charm, very elegant. Great timing, too, since your solution met
a need I just discovered I had....
Note comments marked with --##
(watch line wraps)
# match name as user types
on rawKeyDown pWhich
if the commandKey is down then pass rawKeyDown
# exclude any functions like copy, paste, etc.
if pWhich <= 255 then # for anything that's in ascii range
put the selectedChunk into tSelChunk
if word 2 of tSelChunk <= word 4 of tSelChunk then
# adding a char to the end of the entry buffer
put sEntryBuffer & numToChar(pWhich) into sEntryBuffer
else # inserting a char inside the entry buffer
put numToChar(pWhich) after char word 4 of tSelChunk of
sEntryBuffer
put sEntryBuffer into fld "enterPt"
end if
--## I added the following two lines
--## pList is a global containing the full list of names
put ptList into selectedPts
filter selectedPts with sEntryBuffer & "*"
--## now selectedPts contains only those entries that match
--## this shortens & simplifies the display list
put lineOffset(cr & sEntryBuffer, cr & selectedPts) into
currentLine
if currentLine > 0 then
put selectedPts into fld "pList"
--## instead of putting the whole list into the field
showUserList
set the hilitedLines of field "pList" to currentLine
set the scroll of field "pList" to \
(currentLine - 1) * the effective textHeight of field
"pList"
put the selectedText of fld "pList" into fld "enterPt"
select char (word 2 of tSelChunk) + 1 to -1 of fld "enterPt"
else
hide fld "pList"
set the hilitedline of fld "pList" to 0
put sEntryBuffer into fld "enterPt"
select after char word 4 of tSelChunk + 1 of fld "enterPt"
end if
else # handle all other keys
-- Peter
Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig
More information about the use-livecode
mailing list