views:

655

answers:

2

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)

A: 

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.

JamesW
+1  A: 

ajudou bastante! Valeu

rose