You'd write in your reactor.xml (and any addField() method):
<field alias="clientCode" name="client" validateAs="clientCode"/>
And then you'd be able to do:
<cfset UserRecord = Reactor.createRecord("User").load(userId=1) />
<cfset UserRecord.setClientCode(arguments.newCode)/>
and then
<cfdump var="#UserRecord.isValid('clientCode')#"/>
or maybe
<cfdump var="#UserRecord.isClientCodevalid()#"/>
and get a boolean ?
I'm also thinking a new <config> child element called
<validationClass> which gives the name of a CFC that implements a
particular CFInterface, and that will be used by Reactor to actually
do the check ?
--
Tom
Should the 'default' behaviour be to throw an exception on the set,
for instance ?
It should also be easy to write a custom validator that checked the
'main' validator result, and threw an exception if it failed, so
people can use that pattern if they like.
--
Tom
\o/
> You should be able to get a ValidationResult object which specifies
> what is the result and which fields failed for example.
So UserRecord.isValid() that returns an array of ValidationResult
(fieldName,valueString,isValidBool) ?
As well as isFieldNameValid() ?
The former would follow easily from the latter of course, but choice
could confuse people.
> We could then add ValidationObjects as you said under
> model/reactor/Validations that you can map via
> <validation handler="/model/reactor/Validations/MyHandler"
> name="DogHeadValidation" />
And Reactor automatically pumps in a standard set of Validations ?
In which case Reactor might as well just find all CFC in
m.r.validators and create them without the need for a <validation>
tag, it occurs ... ?
> This would extend a reactor.core.validations.Validation and have a
> "validate" method that you need to first super() to validate standard
> then implement your validation
I assume r.c.v.V would be an interface, right ? So implements not extends ?
I'm not sure they'd be any common code to go in a super class (unless
you wanted to make a FooBarEmailValidator that extends the 'core'
EmailValidator).
I would imagine each Validator just needs a single method:
isValid(Record,fieldNameToCheck) ?
I can (one time) autogenerate a set of default validators that just
wrap isValid() fairly easily from that
(isValid('email',Record[fieldNameToCheck) etc. ).
As a PoC that the system is extensible, add some other ones that use ValidAt.
Until I actually find an example of how to use ValidAt, I'm not sure
if validators based on it should ship in the core or not.
Guess we'll see :-)
--
Tom
Gah.
Reactor should locate all the 'default' validators using something
like that, maybe. But we still need a validation tag so users can add
ones from com.compantname.project.validators.Foo etc.
--
Tom