flex中的必填字段(Required fields in flex)

编程入门 行业动态 更新时间:2024-10-07 00:21:23
flex中的必填字段(Required fields in flex)

我有一个关于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

更多推荐

本文发布于:2023-07-27 04:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1284885.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   必填   flex   Required   fields

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!