Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flex Developer Center /

Exercise 5.4: Styling the Form container

by Trilemetry

Trilemetry
  • Trilemetry, Inc.

Content

  • Use the Form stacked layout skin
  • Add sequence labels
  • Add text prompts
  • Customize the required and error icons

Created

3 May 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash Builder Flex RIA

Requirements

Prerequisite knowledge

  • Exercise 1.1: Setting up Flash Builder and your project files
  • Exercise 3.6: Validating form data
  • User level: Beginning

User level

Beginning

Required products

  • Flash Builder 4.5 Premium (Download trial)

Sample files

  • ex5_04_starter.zip
  • ex5_04_solution.zip

Introduction

The Spark Form container lays out its children in three ways:

  • Horizontal layout, which is the default
  • Stacked layout, and
  • Customized using a grid-based constraint layout

This exercise will focus on the stacked layout. The constraint layout is outside the scope of this course.

In this exercise you will style the Employee Portal: Vehicle Request Form application that you created and customized in the first three days of this series (see Figure 1).

Preview the application.
Figure 1. Preview the application.

In this exercise, you will learn how to:

  • Use the Form stacked layout skin
  • Add sequence labels
  • Add text prompts
  • Customize the required and error icons

Use the Form stacked layout skin

In this section, you will use the stacked layout skin in your form.

  1. Download the ex5_04_starter.zip file if you haven't already and extract the file ex5_04_starter.fxp to your computer.
  2. Open Flash Builder.
  3. Import the ex5_04_starter.fxp file.
  4. Open the ex5_04_starter.mxml file.
  5. Run the application.

You should see the application that you created in Exercise 3.6: Validating form data. Notice that the Form is set in the default horizontal layout (see Figure 2).

The form is in the default horizontal layout.
Figure 2. The form is in the default horizontal layout.
  1. Return to the ex5_04_starter.mxml file.
  2. Below the Styles comment and above the existing Style instance, add a Style block. The application namespaces are automatically added to the Style block.
<fx:Style> @namespace s "library://ns.adobe.com/flex/spark"; @namespace mx "library://ns.adobe.com/flex/mx"; @namespace components "components.*"; </fx:Style>
  1. After the namespace definitions, add a CSS style selector for the Spark FormItem container.
s|FormItem { }
  1. In the FormItem selector block, use the skinClass property to reference the StackedFormItemSkin class.
s|FormItem { skinClass:ClassReference("spark.skins.spark.StackedFormItemSkin"); }

Note: You can also add the skinClass property to each FormItem container in the Form within the MXML code. However, CSS is used to easily apply the skinClass property to all FormItem containers at once.

  1. Save the file and run the application. You should get an error because you also have to apply the stacked skin to the FormHeading control so that the columns match the stacked FormItem controls.
  2. Return to the ex5_04_starter.mxml file.
  3. Before the selector for the Form and FormItem controls, add a selector for the Spark FormHeading control.
  4. In the FormHeading selector block, use the skinClass property to reference the StackedFormHeadingSkin.
s|FormHeading { skinClass:ClassReference("spark.skins.spark.StackedFormHeadingSkin"); }
  1. Save the file and run the application.You should see that the FormItem labels appear above the input controls in the stacked layout (see Figure 3).
  2. Click the Submit Request button.

    Note that the error icons appear, but there is no error message. This occurs because, in a horizontal layout, the error message will display to the right of the TextInput control, but in a stacked layout the error message will display at the top of the container. The error message will not display in the application without the Form selector, so as a best practice, you should add the StackedFormSkin class to the code.

Figure 3. The Form is now set in the stacked layout.
Figure 3. The Form is now set in the stacked layout.
  1. After the namespace definitions and before the selector for the FormHeading control, add a CSS style selector for the Spark Form container.
s|Form { }

In the Form selector block, use the skinClass property to reference the StackedFormSkin class.

s|Form { skinClass:ClassReference("spark.skins.spark.StackedFormSkin"); }
  1. Save the file and run the application. You should see that the application is exactly the same as in Figure 3.
  2. Click the Submit Request button. You should see that the errors now display at the top of the form.

Add sequence labels

In this section, you will add sequence labels which are displayed to the left of FormItem containers.

  1. Return to Flash Builder.
  2. From the components package, open the VehicleRequestForm.mxml file.
  3. Locate the Employee FormItem container.
  4. To the opening FormItem tag, add the sequenceLabel property with a value of 1).
<s:FormItem label="Employee:" sequenceLabel="1)">
  1. To the opening tag for the Office Phone FormItem container, add the sequenceLabel property with a value of 2).
<s:FormItem label="Office Phone:" sequenceLabel="2)">
  1. To the opening tag for the Mobile Phone FormItem container, add the sequenceLabel property with a value of 3).
<s:FormItem label="Mobile Phone:" required="true" sequenceLabel="3)">
  1. To the opening tag for the Pickup Date FormItem container, add the sequenceLabel property with a value of 4).
<s:FormItem label="Pickup Date:" sequenceLabel="4)">
  1. To the opening tag for the Return Date FormItem container, add a sequenceLabel property with a value of 5).
<s:FormItem label="Return Date:" sequenceLabel="5)">
  1. Save the file and run the application.

    You should see the sequence numbers in front of each FormItem label (see Figure 4).

The sequence labels are added to each FormItem control.
Figure 4. The sequence labels are added to each FormItem control.

Add text prompts

In this section, you will add text prompts to the form to describe the input controls. The prompt property is supported by the Spark TextInput and TextArea controls.

  1. Return to the VehicleRequestForm.mxml file in Flash Builder.
  2. Locate the phone TextInput control in the Office Phone FormItem tag block.
  3. To the TextInput control, add the prompt property with a value of Select employee.
<s:TextInput id="phone" text="{dropDownList.selectedItem.phone}" prompt="Select employee"/>
  1. Save the file and run the application. You should see the text prompt in the Office Phone text field (see Figure 5).
The text prompt in the Office Phone field.
Figure 5. The text prompt in the Office Phone field.
  1. 5.Click in the Office Phone input control area. The prompt disappears when the input gets focus.
  2. Leave the Office Phone input control area black and click in the Mobile Phone input control. Note that the text prompt reappears when the input control loses focus and no value is entered.

Customize the required and error icons

The Spark FormItem container supports customization of the required and error fields. You can use a custom icon image and change the background color and text properties. In this section, you will customize the required and error icon images.

  1. Return to VehicleRequestForm.mxml file in Flash Builder.
  2. To the opening tag of the Mobile Phone FormItem container, add the requiredIndicatorSource property and assign the value to assets/required.png .
<s:FormItem label="Mobile Phone:" required="true" sequenceLabel="3)" requiredIndicatorSource="assets/required.png">
  1. Save the file and run the application.

    You should see the newly customized required icon (see Figure 6).

The customized required icon.
Figure 6. The customized required icon.
  1. Without entering a value in the Mobile Phone field, click the Submit Request button. Note the yellow triangle with the exclamation point. This is the default error icon (see Figure 7).
The default error icon.
Figure 7. The default error icon.
  1. Return to the VehicleRequestForm.mxml file.
  2. To the opening Mobile Phone FormItem tag, add the errorIndicatorSource property and assign the value to assets/invalid.png.
<s:FormItem label="Mobile Phone:" required="true" sequenceLabel="3)" requiredIndicatorSource="assets/required.png" errorIndicatorSource="assets/invalid.png">
  1. Save the file and run the application.
  2. Without entering a value in the Mobile Phone field, click the Submit Request button.

    You should see the newly customized error icon (see Figure 8).

The customized error icon.
Figure 8. The customized error icon.

In this exercise you styled the Employee Portal: Vehicle Request Form application that you created and customized in the first three days of this series.

Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License+Adobe Commercial Rights

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

More Like This

  • Exercise 1.1: Setting up your project files
  • Exercise 1.2: Creating an application user interface
  • Exercise 1.3: Generating an email address using data binding
  • Exercise 1.4: Adding data to your application
  • Exercise 1.5: Experimenting with container layouts
  • Exercise 1.6: Creating MXML custom components with ActionScript properties
  • Exercise 2.5: Retrieving and handling data with the RemoteObject object
  • Exercise 2.6: Separating the model, view, and controller
  • Exercise 2.7: Creating an ActionScript class and instances
  • Exercise 2.8: Creating an ArrayCollection of value objects

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement