Associating Validation Rules Dynamically

18 views
Skip to first unread message

Cameron Childress

unread,
Mar 20, 2014, 4:01:43 PM3/20/14
to valida...@googlegroups.com
For now I have some server side validation that happens inside my beans but I'm rethinking this for a new project and have this concept in my head and I'm trying to figure out if it's an insane idea.

I'd like to be able to use the same bean property based rules and dynamically assign them to form fields on both the server and client side. Let's say I have already established rules for Address.cfc where the property 'CountryCode" was required and had to be a 3 char intentional Country code.

Here is a very contrived example. In reality I'd be centralizing the aliasRule() stuff someplace:


My goals are:

1) Still define rules centrally in one location
2) Decouple form field naming vs rule definitions
3) Use this dynamically created context on both the server and client side

It looks like addRule() gets me part of the way there. Thoughts? Is this a bad idea? Can I already accomplish this in the way I describe or maybe a different way? 

Near the addRule() docs, they say "We are looking at ways of making it simpler to define validation rules via CFM". But it does look like VT may have lost some steam on new releases lately. 

Any thoughts?

-Cameron

--
Cameron Childress
--
p:   678.637.5072
im: cameroncf

John Whish

unread,
Mar 26, 2014, 3:43:17 PM3/26/14
to valida...@googlegroups.com
Hi,

As far as I can recall then addRule is the only thing in VT that would get you close to doing this. I haven't heard of anyone doing something similar to what you're proposing. it's an interesting idea though although it seems from a first read that it would be be harder to maintain than using the 'traditional' way.


--
You received this message because you are subscribed to the Google Groups "ValidateThis" group.
To unsubscribe from this group and stop receiving emails from it, send an email to validatethis...@googlegroups.com.
To post to this group, send email to valida...@googlegroups.com.
Visit this group at http://groups.google.com/group/validatethis.
For more options, visit https://groups.google.com/d/optout.

Cameron Childress

unread,
Mar 28, 2014, 1:22:44 PM3/28/14
to valida...@googlegroups.com
I'm actually part of the way down the road with this now and it's looking like it's possible by supplying my own BOValidator and tampering with loadRulesFromExternalFile() to use my own dynamic context prior to loading rules from the outside. I can inject any recombination of existing rules from there.

It does seem like it could be a bit more work but I already have put all my form fields into (imported) Custom Tags to help manage formatting and other things, so a form can more like this:

<ui:Form id="myFormContextName" >
  <ui:TextInput label="Name" vtrule="user.name" >
  <ui:TextInput label="Child's Name" id="kidname" vtrule="user.name" >
  <ui:TextInput label="College" vtrule="institution.name" >
</ui:Form>

This totally contrived example can (potentially) make a dynamic validation set with a context of "myFormContextName" that contains the existing rules for User():name and Institution():name mapped to three separate and differently named fields. I just drop the mechanics of it into my custom tags and I'm good to go.

It would also allow me to define and change out validation rules on the fly per client/site/etc on a codebase that needs to be pretty flexible.

I'm still just experimenting with this. But it's not as much work as my first (also very contrived) example may have indicated.

-Cameron

John Whish

unread,
Mar 28, 2014, 5:13:26 PM3/28/14
to valida...@googlegroups.com
Good work! Interesting stuff :)
Reply all
Reply to author
Forward
0 new messages