23 May 2011
Beginning
The Spark Form container lays out its children in three ways:
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).
In this exercise, you will learn how to:
In this section, you will use the stacked layout skin in your form.
You should see the application that you created in Exercise 3.6 (Validating form data). Note that the Form is set in the default horizontal layout (see Figure 2).
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>
FormItem container.s|FormItem
{
}
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.
skinClass property to reference the StackedFormHeadingSkin.s|FormHeading
{
skinClass:ClassReference("spark.skins.spark.StackedFormHeadingSkin");
}
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.
s|Form
{
}
skinClass property to reference the StackedFormSkin class.s|Form
{
skinClass:ClassReference("spark.skins.spark.StackedFormSkin");
}
In this section, you will add sequence labels which are displayed to the left of FormItem containers.
FormItem container.FormItem tag, add the sequenceLabel property with a value of 1).<s:FormItem label="Employee:"
sequenceLabel="1)">
FormItem container, add the sequenceLabel property with a value of 2).<s:FormItem label="Office Phone:"
sequenceLabel="2)">
FormItem container, add the sequenceLabel property with a value of 3).<s:FormItem label="Mobile Phone:"
required="true"
sequenceLabel="3)">
FormItem container, add the sequenceLabel property with a value of 4).<s:FormItem label="Pickup Date:"
sequenceLabel="4)">
FormItem container, add a sequenceLabel property with a value of 5).<s:FormItem label="Return Date:"
sequenceLabel="5)">
You should see the sequence numbers in front of each FormItem label (see Figure 4).
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.
phone TextInput control in the Office Phone FormItem tag block.TextInput control, add the prompt property with a value of Select employee.<s:TextInput id="phone"
text="{dropDownList.selectedItem.phone}"
prompt="Select employee"/>
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.
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">
You should see the newly customized required icon (see Figure 6).
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">
You should see the newly customized error icon (see Figure 8).
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. In the next exercise you will create a skin for the Employee Portal application and use the provided skinning components to configure the application.
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.