我有一个简单的登录表单,用户输入userSAP否(必须是数字)和密码(最少8个字符)。我已经为每个字段进行了验证。我想检查验证是否在它从LoginMode_Default状态改变为PerviewMode状态之前通过。 用户登录后,会向用户显示欢迎信息。Flex:如何在验证有效后更改登录表单中的状态?
在我的代码中,当用户单击登录按钮时,我调用validateLogin()函数检查字段是否有效。如果有效,则将currentState设置为PerviewMode状态。
在PerviewMode用户可以点击注销,这就要求注销()函数返回到LoginMode_Default状态。
然而,当我点击退出链接,它可以追溯到登录表单,但用户名和密码字段被概括为红色。我怎样才能回到登录表单没有领域变得红色?我做得对吗?有没有更好或正确的方法来做到这一点?有人能帮我解决这个问题吗?谢谢:)
我的验证码
<fx:Declarations>
<s:NumberValidator id="userSAPValidator"
property="text"
required="true"
domain="int"
notAnIntegerError="Should not conatin any decimal"
allowNegative="false"
negativeError="Should not contain negative values"
parseError="Enter only numbers without space"
source="{userSAP_field}"/>
<mx:StringValidator id="userPasswordValidator"
property="text"
required="true"
minLength="8"
tooShortError="password must at least be 8 characters"
source="{userPassword_field}"/>
</fx:Declarations>
我在MXML状态:
<s:states>
<s:State name="LoginMode_Default"/>
<s:State name="PerviewMode"/>
</s:states>
我的登录表单MXML:
<s:BorderContainer id="login_BC" x="1" y="1" width="223" height="134"
x.LoginMode_Default="2" y.LoginMode_Default="9"
height.LoginMode_Default="152" height.PerviewMode="40">
<s:Form id="loginForm" x="5" y="7" width="212" height="133"
x.LoginMode_Default="4" y.LoginMode_Default="5" excludeFrom="PerviewMode">
<s:layout>
<s:BasicLayout/>
</s:layout>
<s:Label x="0" y="14" width="52" height="18" text="SAP no :" paddingTop="5"/>
<s:TextInput id="userSAP_field" x="74" y="10" width="108"/>
<s:Label x="0" y="52" text="Password :" paddingTop="5"/>
<s:TextInput id="userPassword_field" x="73" y="48" width="109" height="21" displayAsPassword="true"/>
<s:Button id="loginButton" x="6" y="82" label="Login" click="validateLogin()" />
</s:Form>
<s:HGroup includeIn="PerviewMode" width="245" height="41">
<s:Label id="welcome_text" text="Welome your name" paddingTop="12" paddingLeft="10"/>
<mx:LinkButton label="logout" click="logOff()" paddingTop="6"/>
</s:HGroup>
</s:BorderContainer>
我validateLogin功能:
private function validateLogin():void {
var vResult1:ValidationResultEvent;
var vResult2:ValidationResultEvent;
vResult1 = userPasswordValidator.validate();
vResult2 = userSAPValidator.validate();
if (vResult1.type==ValidationResultEvent.VALID && vResult2.type == ValidationResultEvent.VALID) {
this.currentState = "PerviewMode";
}
else{
this.currentState = "LoginMode_Default";
}
}
我的注销功能:
private function logOff():void {
this.currentState = "LoginMode_Default";
userPassword_field.text ="";
userSAP_field.text ="";
}
这可能帮助.. http://stackoverflow.com/questions/2243582/how-to-remove-validation-programmatically-from-flex-component – 2013-03-04 10:29:24