FilterFunctions
by Susan Rayl, NeXT Developer Training Team

Overview

This MiniExample demonstrates how to modify the filter function of a text object. A text filter function is the input filter for the Text object which allows the programmer to monitor (and control or modify), the characters entered into a Text object or a TextField object. 

As Concepts says, 

Unlike a character filter, which only receives the individual character that's entered, a text filter additionally receives information about the state of the Text object.  Based on this information, the text filter can change a number of variables including the content of the entered or existing text and the location of the insertion point.

In this application, different text filter functions are attached to the fieldEditor of the Window depending on which TextField is the firstResponder.  See the on-line documentation for additional information about filter functions. The application implements the text filtering in three different ways. See the description below for the major classes in this application for more detail about the different methods of modifying the filter function for a text object.

Program Organization

Building the nib file
The nib file contains one Window with four TextFields, each of which requires a different format of data: text, dates, time or social security number.

Major Classes in the Application

NameTextField	For the name TextField, the filter function is set when the field becomes the firstResponder (after a mouse click or a Tab into the field).  This works but isn't extremely elegant.  Look in NameTextField.[hm] for details.

DateTFCell	These two classes support the TextField which requires data in the form of a
DateTextField	date. For the date TextField, the filter function is set by a custom Cell class when that cell is notified that the field is being edited.  This solution is symmetrical and preferred (by me, at least).  Again, look in the source for the DateTextField class.

FilterTextCell	This is a generic version of the DateTFCell object. This object can be subclassed and used to support many different filter functions. As with this application, there is the potential for a need for several different filters, and we wouldn't want to have to reinvent the code everytime. Isn't object oriented programming wonderful!?!

TimeTFCell	For the time and social security number TextFields, the filter function is also
TimeTextField	set by a custom Cell class.  However, an abstract Cell class has been
SSTFCell	implemented (Filter TextCell), gathering filter-setting functionality in one
SSTextField	encapsulated, reusable class.  Much better.

Topics Of Interest

We will leave it up to the reader to modify this program in the following ways:

· Add another text item with a different filter for entering phone numbers.
· Modify the current example, such that it checks the data that the user types in for valid days, months, and years.
· Modify the current example, such that it checks and prevents invalid time data.
· Create a scrollview that requires a filter function.

Other Files

Filters.nib		The main nib file, the user-interface of the application.

Filters_main.m,	Created by Interface Builder.
IB.proj,
Makefile,
Filters.iconheader

Other References

Please refer to the text object reference pages for specific information about filter functions.

Valid valid  for 1.0
Valid valid  for 2.0