显示容器时如何强制 Flex 验证
我有一个 Flex 3 应用程序,其视图位于视图堆栈中,并且该视图只能在请求时创建。 我已经为视图上的每个控件声明了验证器,并且创建了一个名为 checkAllValid() 的方法,该方法运行 Validator.validateAll()。 当我实际使用控件(使用 Change 或 focusOut 事件)时,这非常有用,但是如何在视图首次向用户显示时运行 checkAllValid() ,以便立即向用户显示无效的内容数据填充在控件中?
我尝试将调用放入视图本身的各种事件中(例如,creationComplete、updateComplete、show、activate 等),但当我启动应用程序时,它总是显示以下错误:
'必须在以下情况下指定源属性 :指定了 property 属性。'
我也尝试将视图上的creationPolicy 设置为“all”,但这没有帮助。
有些验证器仅在表单处于某种状态时才启用,但我通过注释掉除这个最简单的验证器之外的所有验证器来消除潜在的问题:
<mx:Array id="validators"><mx:StringValidator id="val_Address1" source="{Address1}" property="text" required="true" triggerEvent=""/></mx:Array>
checkAllValid() 方法非常简单,如下所示:
private function checkAllValid():void{
var validationErrors: Array = Validator.validateAll(validators);
}
我也尝试过直接调用单个验证器而不是使用 validateAll,结果是相同的。
请帮忙! 必须有一种方法可以强制视图在显示时进行验证......
(顺便说一句,它位于 Cairngorm MVC 框架中,并且我将数据绑定到控件)
I have a Flex 3 app with a view in a viewstack, and that view must only be created when requested. I have declared validators for each of the controls on the view and I have created a method called checkAllValid() which runs Validator.validateAll(). This works great when I'm actually using the controls (using the change or focusOut events), but how can I get checkAllValid() to run when the view is first displayed to the user, so that they are immediately shown what is invalid once the data is populated in the controls?
I have tried putting the call in various events on the view itself (e.g. creationComplete, updateComplete, show, activate, etc.) but it always shows the following error when I start the application:
'The source attribute must be specified when the property attribute is specified.'
I have also tried setting the creationPolicy on the view to "all" but this does not help.
Some of the validators are only enabled when the form is in a certain state, but I have eliminated that as being the potential problem by commenting out all of my validators except for this most simple one:
<mx:Array id="validators"><mx:StringValidator id="val_Address1" source="{Address1}" property="text" required="true" triggerEvent=""/></mx:Array>
The checkAllValid() method is as simple as follows:
private function checkAllValid():void{
var validationErrors: Array = Validator.validateAll(validators);
}
I have also tried calling the single validator directly rather than using validateAll and the result is the same.
Please help! There must be a way I can force the view to validate when it is shown....
(by the way it's in the Cairngorm MVC framework and I have data bound to the controls)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
知道了! 我将类似的验证器添加到另一个视图中,它们工作得很好。 有什么区别? 调用 checkAllValid() 的方法是在内部容器(而不是主视图组件)的creationComplete 事件上调用的。
所以最终这与验证本身无关——只是我没有完全理解创建顺序。
我将把问题留在这里,以防万一有人在创建顺序时遇到类似的问题。
Got it! I added similar validators to another view and they worked fine. What was the difference? The method that called checkAllValid() was being called on the creationComplete event of an internal container - not the main view component.
So in the end it was nothing to do with the validation itself - just me not fully understanding the creation order.
I'll leave the question on here just in case someone encounters a similar problem with the creation order.