OK, this shouldn’t be so bad but it’s
not as perfect as you want. The process will be better in 2.0.
In your custom validator I’m
assuming you overrode doValidation. Rename that method to something else,
like
function doValidationWithRule(value :
Object, rule : Rule) : Void
{
//whatever logic you had in
doValidation should be here (except for a call to super.doValidation)
}
So now you take the rule as parameter and
you can do the same logic you had in there before. Now of course you need
to somehow call the doValidationWithRule method and pass in the value, but you
can do that with the validate event and the properties that come on it.
<inps:CustomTextValidator field="CheckModel.String"
validate=”event.validator.doValidationWithRule(event.value, stringRule)”
/>
And there you go. The doValidation
method of the superclass will run, which will check your required
properties. And if you want you could put additional logic in there that
didn’t require the rule. But to pass in information to the
validator that was not a hard-coded string you create another method on the
validator and pass in that info during the validation process.
Hope this helps,
Matt
From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of kevmclachlan79
Sent: Thursday, June 02, 2005 3:01
AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Passing an
object into a custom validator
Hi all,
I am having a bit of a problem with validators in
my application. The
problem is that I am trying to get a object to a
custom validator so
that I can validate based on properties of the
object.
I have a rule object that contains various
properties about the rule
which I need access to in the validator (eg max,
min, mandatory). The
lack of binding or an id in the validator means
that I cannot access
the validator directly and assign it to the
validators rule
attribute.
I just need some way to get the object in the mxml
into my custom
validators (I have 3 validators, extending the
number, date and string
validator classes) so it can use the objects
properties to validate.
The mxml I have is as follows and it is the
"stringRule" object I need
passed in to the validator somehow:
var stringRule: Rule;
function updateRules() {
stringRule =
validationTestView.getRule('StringMaxMin'); // This
view returns a Rule object for use in the custom
validator
}
....
<mx:Model id="CheckModel">
<Date>{dateInput.text}</Date>
<String>{stringInput.text}</String>
<Number>{numberInput.text}</Number>
</mx:Model>
....
<mx:Form>
<mx:FormItem
label="String validator : " color="#FFFFFF">
<mx:TextInput id="stringInput" width="200"
color="#000000"/>
</mx:FormItem>
</mx:Form>
<inps:CustomTextValidator
field="CheckModel.String"
rule="{stringRule}" /> <!--
Contains a rule class variable to store
the Rule object -->
Any help would be gratefully appreciated.
Thanks in advance,
Kevin
Yahoo! Groups Links