简体   繁体   中英

Flex 4.5 alert message for textInput

Created two textfield and I have to validate it and display the error msg in the alert box. In 4.5 mx.controls.Alert is not supported. I tried including mx from the source path. Kindly help me how to show the alert box by validating the textfield is empty..

<code>

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" title="validation">



<fx:Declarations>
        <fx:Component className="AlertMsg">
            <s:SkinnablePopUpContainer x="70" y="100">
                <s:TitleWindow title="My Message" close="close()">
                    <s:VGroup horizontalAlign="center" paddingTop="8" paddingBottom="8" paddingLeft="8" paddingRight="8" gap="5" width="100%">
                        <s:Label text="My alert message text here..."/>
                        <s:Button label="OK" click="close()"/>
                    </s:VGroup>
                </s:TitleWindow>
            </s:SkinnablePopUpContainer>
        </fx:Component>
    </fx:Declarations>



    <s:layout>
            <s:VerticalLayout paddingTop="5" paddingBottom="5" paddingLeft="5" paddingRight="5" gap="10"
                              horizontalAlign="center" verticalAlign="top"/>
        </s:layout>

    <s:TextInput id="firstName"/>
    <s:TextInput id="zipCodeInput"/>
    <s:Button label="Show Alert" click="(new AlertMsg()).open(this, false)"/>

</s:View>

</code>

Here alert is displayed in fx:declaration. How to show the alert msg by validating the textfield.. Kindly help

add a click handler on your button "Show Alert" instead of directly showing your alert box. From there, validate the value of your TextInput fields. If it's empty, show your alert.

<fx:Script>
   <![CDATA[        
      private function validateField() : void {
          if (firstName.text == "" || zipCodeInput.text == "")
              new AlertMsg().open(this, false);
      }
   ]]>   
</fx:Script>


<s:Button label="Show Alert" click="validateField()"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM