Text search box

This lesson demonstrates how to search for a piece of text.

The returnInField message

The returnInField message is sent to a field when the selection is in the field and the user presses the Return key.

The find command

The find command is a simple search. By default, it finds and highlights the next instance where all the words in the field appear. It starts searching on the current card, then continues to search other cards in the current stack.  The default form of the search doesn't require all the search words to appear in the same order as specified, or even in the same field, as long as they are all found on the same card.

The returnInField handler

on returnInField
	if me is empty then
		## nothing to find
		find the text of me 
	end if
end returnInField

The keyword me refers to the current object: the object whose script contains the handler that is executing. In this example, me is a reference to the field, because the returnInField handler is in the field's script. If the field is empty, there is nothing to find, so the handler just beeps. Otherwise, the handler uses the find command to search for whatever text is in the field.

If the Search field is in the stack to be searched, the field's dontSearch property must be set to true. Otherwise, it will try to find the search text in itself. (Of course, it will succeed, since the Search field does contain the search text, so it will never find it anywhere else.)

Searching other stacks

Suppose you want the Search field to look in another stack. For example, the Search box may be in a separate Search palette window, and you want to search some other "document" window. The find command operates on the current stack, so if you set the defaultStack property to the stack you want to search, the Search field will look in that stack instead:

set the defaultStack to "My Records Window"
find the text of me ## searches in "My Records Window"

If your Search field is contained in a palette, to search the front most editable stack:

set the defaultStack to the topStack

If there are no editable stack windows open, it searches modeless dialog boxes (like the Documentation windows).


Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.