Log in / Register
Home arrow Computer Science arrow Learn BlackBerry 10 App Development
< Prev   CONTENTS   Next >


You can use a label control to display a single or multiple lines of read-only text by setting its text property. You have already seen labels in action in the previous examples (see Listing 4-7 to Listing 4-9).


A TextField is a single-line control that accepts text input. A TextField has fixed height and variable width. Just like a label, you can control the text styling using a TextStyleDefinition object (in other words, all the techniques described in the previous sections apply to text fields). You can specify how the text field behaves in relation to its text input by specifying its inputMode property. The following are some common values:

n TextFieldInputMode.Default: This is the default input mode.

n TextFieldInputMode.Text: An input mode for a wide variety of text.

n TextFieldInputMode.EmailAddress: An input mode for e-mail addresses.

n TextFieldInputMode.Password: An input mode for passwords.

n TextFieldInputMode.NumericPassword: An input mode for numeric passwords.

n TextFieldInputMode.Url: An input mode for URLs.

n TextFieldInputMode.PhoneNumber: An input mode for phone numbers.

In fact, a TextFieldInputMode corresponds to default values for input and content flags. Input flags determine how the text that users type is parsed and interpreted by the text field. Content flags determine how the text that users type is displayed. In practice, using one of the default

TextFieldInputMode types to preset the flags is more than adequate, and you should rarely need to

set the input and content flags directly. The inputMode property value also determines the kind of virtual keyboard displayed to the user when entering text. For example, TextFieldInputMode.Text is the most flexible and suitable for a wide variety of text. This mode also includes word suggestions to help users type faster. The other input modes are optimized for specific tasks such as writing e-mails or entering numeric values. For example, Figures 4-7 and 4-8 illustrate the TextFieldInputMode.

EmailAddress and TextFieldInputMode.NumericPassword respectively.

Figure 4-7. A virtual keyboard corresponding to an e-mail address input (image source: BlackBerry)

Figure 4-8. A virtual keyboard corresponding to numeric password input (image source: BlackBerry)

You can capture a TextField's input using its input grouped property, as illustrated in Listing 4-11.

Listing 4-11. Text Capture

import bb.cascades 1.2

Page {

Container {

TextField {

id: myField

inputMode: TextFieldInputMode.EmailAddress hintText: "Enter email address"


submitKey: SubmitKey.Go onSubmitted: {

// handle input when submit key is pressed

// by extracting text from myField.text






The submitKey property controls the text that will appear on the virtual keyboard's Submit key (the Submit key is always located on the lower-right side of the virtual keyboard). The property can take one of the following values: SubmitKey.Go, SubmitKey.Join, SubmitKey.Next, SubmitKey.Search, SubmitKey.Send, SubmitKey.Submit, SubmitKey.Done, SubmitKey.Connect, SubmitKey.EnterKey, and SubmitKey.Replace.

You can also use a TextField's hintText property to suggest the purpose of the field to the user when there is no input (see Listing 4-11).

Found a mistake? Please highlight the word and press Shift + Enter  
< Prev   CONTENTS   Next >
Business & Finance
Computer Science
Language & Literature
Political science