Flex - 表單



介紹

表單容器允許您控制表單的佈局,將表單欄位標記為必填或可選,處理錯誤訊息,並將表單資料繫結到 Flex 資料模型以執行資料檢查和驗證。它還允許您使用樣式表配置表單的外觀。

類宣告

以下是 **spark.components.Form** 類的宣告:

public class Form 
   extends Container

公共屬性

序號 屬性及描述
1

invalidElements : Array

[只讀] 處於無效狀態的後代元素的有序陣列。

公共方法

序號 方法及描述
1

Form()

建構函式。

繼承的方法

此類繼承自以下類:

  • mx.core.Component
  • mx.core.UIComponent
  • mx.core.FlexSprite
  • flash.display.Sprite
  • flash.display.DisplayObjectContainer
  • flash.display.InteractiveObject
  • flash.display.DisplayObject
  • flash.events.EventDispatcher
  • Object

Flex 表單示例

讓我們按照以下步驟檢查在 Flex 應用程式中使用表單的方法,方法是建立一個測試應用程式:

步驟 描述
1 在包 **com.tutorialspoint.client** 下建立一個名為 **HelloWorld** 的專案,如“Flex - 建立應用程式”一章所述。
2 修改 **HelloWorld.mxml**,如下所述。保持其餘檔案不變。
3 編譯並執行應用程式以確保業務邏輯按要求工作。

以下是修改後的 mxml 檔案 **src/com.tutorialspoint/HelloWorld.mxml** 的內容。

<?xml version = "1.0" encoding = "utf-8"?>
<s:Application xmlns:fx = "http://ns.adobe.com/mxml/2009"
   xmlns:s = "library://ns.adobe.com/flex/spark"
   xmlns:mx = "library://ns.adobe.com/flex/mx
   width = "100%" height = "100%" minWidth = "500" minHeight = "500">  
   
   <fx:Style source = "/com/tutorialspoint/client/Style.css" />
   <fx:Declarations>
      <mx:StringValidator source = "{fname}" property = "text" 
         minLength = "4" maxLength = "12" />
      <mx:PhoneNumberValidator source = "{phone}" property = "text" />
      <mx:EmailValidator source = "{email}" property = "text" />
   </fx:Declarations>
   
   <s:BorderContainer width = "630" height = "480" id = "mainContainer" 
      styleName = "container">
      <s:VGroup width = "100%" height = "100%" gap = "50" 
         horizontalAlign = "center" verticalAlign = "middle">
         <s:Label id = "lblHeader" text = "Layout Panels Demonstration" 
            fontSize = "40" color = "0x777777" styleName = "heading" />
         
         <s:Panel id = "formPanel" title = "Using Form"
            width = "500" height = "300" 
            includeInLayout = "true" visible = "true">
            
            <s:Form >						
               <s:FormItem label = "First name">
                  <s:TextInput id = "fname" width = "200" />
               </s:FormItem>
               
               <s:FormItem label = "E-mail">
                  <s:TextInput id = "email" width = "200" />
               </s:FormItem>
               
               <s:FormItem label = "Phone">
                  <s:TextInput id = "phone" width = "200" />
               </s:FormItem>
            </s:Form>
         </s:Panel>
      </s:VGroup>	 
   </s:BorderContainer>	
</s:Application>

準備好所有更改後,讓我們以正常模式編譯並執行應用程式,就像我們在“Flex - 建立應用程式”一章中所做的那樣。如果您的應用程式一切正常,它將產生以下結果:[線上嘗試]

Flex Form
flex_layout_panels.htm
廣告

© . All rights reserved.