Re: How do I…
Bob Sneidar
bobs at twft.com
Tue May 15 12:09:48 EDT 2012
This is what I did. It's for a datagrid but you can modify it for your purposes. It does not go by the second character, but instead waits a certain time (.75 seconds) with messages each time a key is pressed. If no key is pressed during that time it executes the filter handler.
local lSavedData, lSavedID
--> all handlers
ON rawKeyUp
IF the text of me is not empty THEN
show button "btnCloseFind"
put the ticks into theLastTime
wait .75 seconds WITH messages
filterDataGrid
ELSE
put empty into gStartTime
hide button "btnCloseFind"
IF lSavedData is an array THEN
set the dgData of group "dgTableData" to lSavedData
put empty into lSavedData
END IF
exit to top
END IF
pass rawKeyUp
END rawKeyUp
ON filterDataGrid
-- Get the value
put the text of me into theValue
-- save the selection
put the dgHilitedIndex of group "dgTableData" into theIndex
put the dgDataOfIndex[theIndex] of group "dgTableData" into theRowA
put theRowA["uniqueid"] into lSavedID
-- Save the datagrid data
IF not (lSavedData is an array) THEN
put the dgData of group "dgTableData" into theDataA
put theDataA into lSavedData
ELSE
put lSavedData into theDataA
END IF
-- convert the datagrid array to key text
put altPrintKeys(theDataA) into theText
-- filter the data
filter theText WITH tab & "*" & tab & theValue & "*"
-- convert the text back to an array
put altKeysToArray(theText) into theDataA
set the dgData of group "dgTableData" to theDataA
hiliteRecord
dispatch "selectionChanged" to group "dgTableData"
-- set the dgFocus of group "dgTableData" to true
END filterDataGrid
ON restoreDataGrid
put empty into field "FindBar"
set the dgData of group "dgTableData" to lSavedData
hiliteRecord
set the dgFocus of group "dgTableData" to true
put empty into lSavedData
put empty into lSavedID
END restoreDataGrid
ON hiliteRecord
dispatch findIndex to group "dgTableData" WITH "uniqueid", lSavedID
put the result into theFoundIndex
IF theFoundIndex = 0 THEN
set the dgHilitedLine of group "dgTableData" to 1
ELSE
set the dgHilitedIndex of group "dgTableData" to theFoundIndex
END IF
END hiliteRecord
Bob
On May 15, 2012, at 8:50 AM, Dan Friedman wrote:
> I could use a little help... Say you have a search field. In the script of that field you use the rawKeyUp message to search for whatever it is they typed (search your database, compile a list and display it neatly in a list). How would you structure this so that when they typed a second character in the search field, the executing rawKeyUp will halt and start over using the updated search string?
>
> Thanks in advance!
> -Dan
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list