我有一个关于flex的问题。 我有一个表格,需要电子邮件。 我用Google搜索了这个并找到了以下解决方案:
<mx:FormItem label="Email" id="emailFormItem" width="100%" styleName="formEven" required="true"> <mx:TextInput id="emailTextInput" width="100%" text="{user.email}"/></mx:FormItem>问题是,当我按下确定时,仍然会进行通话。 我知道你必须自己验证以下内容,但有没有人知道如何验证字段?
解:
我找到了一个解决方案:
您可以为要验证的每个字段创建验证器,然后创建此函数:
private function isValid():Boolean { var failedValidators:Array = Validator.validateAll([emailValidator, userNameValidator, languageValidator, firstNameValidator, lastNameValidator]); return failedValidators.length == 0; }这可以关闭。
I've got a question about flex. I have a form and the email is required. I googled this and found the following solution:
<mx:FormItem label="Email" id="emailFormItem" width="100%" styleName="formEven" required="true"> <mx:TextInput id="emailTextInput" width="100%" text="{user.email}"/></mx:FormItem>The problem is that when I press ok the call is still made. I know you have to validate the following by yourself but does anyone has an idea how I can validate the field(s)?
Solution:
I've found a solution for this:
You can create a validator for each field you want to validate and then create this function:
private function isValid():Boolean { var failedValidators:Array = Validator.validateAll([emailValidator, userNameValidator, languageValidator, firstNameValidator, lastNameValidator]); return failedValidators.length == 0; }This can be closed.
最满意答案
我通常做的是创建一个名为isSubmitEnabled或isFormComplete的方法。 我在keyUp上调用它所需的每个字段并检查所有字段中的值(以及我想要做的任何其他验证)然后只要一切都检出我设置提交按钮以启用,否则我设置提交按钮被禁用。 只要你在开始时禁用按钮,那么你应该好好去。
我已经多次使用过这种方法,发现它最容易使用,特别是维护。 我将查看文档,看看我是否可以看到您可以使用表单项上的必需属性做什么。
更新:
根据文件:
此属性仅控制指示器显示。 如果需要输入验证,则必须将验证器附加到子项。
你想要的是mx.validators.Validator( http://livedocs.adobe.com/flex/3/langref/mx/validators/Validator.html )
<mx:Validator id="reqValid" required="true" source="{fname}" property="text" valid="handleValid(event)" invalid="handleValid(event)"/>请参阅该链接上的代码示例以了解如何使用它。 这个例子实际上正是你想要的。 HTH
what I generally do is create a method called something like isSubmitEnabled or isFormComplete. I call it on keyUp on every field that is required and check for values in all of the fields (and any other validation I want to do) and then as long as everything checks out I set the submit button to be enabled otherwise I set the submit button to be disabled. As long as you disable the button when you start then you should be good to go.
I have used this method several times and find it to be the easiest to use and especially to maintain. I will look at the docs and see if I can see what you can do with the required attribute on the form item though.
Update:
According to the docs:
This property controls the indicator display only. You must attach a validator to the children if you require input validation.
What you want is mx.validators.Validator (http://livedocs.adobe.com/flex/3/langref/mx/validators/Validator.html)
<mx:Validator id="reqValid" required="true" source="{fname}" property="text" valid="handleValid(event)" invalid="handleValid(event)"/>See the code examples on that link to see how to use it. The example is actually exactly what you are looking for I think. HTH
更多推荐
发布评论