develop wherever and whenever you want...
Docs > TextField Class Reference

TextField Class Reference

Summary 
A text field displays and allows the user to edit a single line of information. Text content can be set the same way as a label using setText(), getText(), setFont(), setTextAlignment(), and setTextColor(). The control provides for optional events which can be registered to receive selection changes or content changes as the user edits the text field.

void enableTextEvents(enable) 
void onTextChange(handler) 
void onSelectChange(handler)

Example 
root = new View("ipad-portrait"); 
field = root.createTextField(root.width, 100); 
field.enableTextEvents(true);

function textChange(sender) { 
document.writeln(sender.getText()); 

field.onTextChange(textChange); 
document.wait(); 


enableTextEvents 
Enable or disable dispatching of text and selection change events

void enableTextEvents(enable)

Parameters 
enable - true to enable text event dispatching, false to disable

Return Value 
none

Notes 
Text events must be enabled before calls to text change or selection change handlers are made. This method is common between TextField and TextView objects.


onTextChange 
Register event handler to receive text change notifications in a text field or a text view

void onTextChange(handler)

Parameters 
handler - function to call when text changes

Return Value 
none

Notes 
Signature of the function to receive text events is below. The event source (sender) is passed to the function allowing the same function to be used to receive text change events from multiple text fields or text views. Text events must be enabled using enableTextEvents() before these events are delivered.

void <handler>(sender)

sender - view object that originated text change


onSelectChange 
Register event handler to receive selection change notifications in a text field or a text view

void onSelectChange(handler)

Parameters handler - function to call when selection changes

Return Value 
none

Notes 
Since there is no mechanism to receive the current selection range for a text field or view, this function is reserved for future use.

TextView Class Reference

Summary 
A text view is identical to a text field, except it allows the user to change multiple lines. Please see the TextField class reference for information about text view objects.