Re: [ValidateThis] skip fields not present?

7 views
Skip to first unread message

Bob Silverberg

unread,
Mar 15, 2011, 11:10:13 AM3/15/11
to valida...@googlegroups.com, validate...@googlegroups.com
I don't believe that is currently possible for server-side
validations. It does work on the client side - if a form field
doesn't exist it's just ignored, and you can also manually flag form
fields to be ignored (which might be what you saw in the docs).

I don't think this would be a big deal to address, probably just a
couple of lines of code here and there, but it does sound like a bit
of an edge case to me, and I wouldn't want it to be abused. Your case
sounds valid, but I wouldn't want people building one huge rules file
for all of their objects and just counting on the framework to ignore
properties if they don't exist. So I'm not totally sure that it's a
good thing to add to the framework.

What do other folks think?

Bob

On Tue, Mar 15, 2011 at 9:41 AM, Jim Priest <pri...@thecrumb.com> wrote:
> I'm working on kind of an edge case here...
>
> I have a load of PDF's and noticed they return a nice PDF object so I
> was thinking I can run those through ValidateThis for some high level
> checks before saving them.
>
> Validation works but given the # of forms I have and the possible # of
> fields in them I'm wondering...
>
> What I'd like to do is say,  "Validate this if the property exists"
> because I don't really want to write contexts for each form I have and
> the fields in it.  Then I could simply have a huge rules file with all
> the possible fields...
>
> <objectProperties ignoreMissingProperty = "true">   :)
>
> Is there a way to do that with ValidateThis? I thought I read in the
> docs somewhere about ignoring rules or something like that but can't
> find it this morning.
>
> Thanks!
> Jim
>
> --
> You received this message because you are subscribed to the Google Groups "ValidateThis" group.
> To post to this group, send email to valida...@googlegroups.com.
> To unsubscribe from this group, send email to validatethis...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/validatethis?hl=en.
>
>

--
Bob Silverberg
www.silverwareconsulting.com

Bob Silverberg

unread,
Jun 20, 2011, 2:16:09 PM6/20/11
to validate...@googlegroups.com
I wanted to bring this to the -dev list for discussion. The question
is: Should VT ignore rules for properties that do not exist?
Currently it does not ignore them - it throws an exception. I can see
how it could be useful for the FW to ignore missing properties in some
cases, but I'm not sure if it's a good practice.

If we do like the idea we could consider adding a config option to
turn this feature on and off, but I'm also wary of adding more config
options.

What do folks think about this?

Cheers,
Bob

Marc Esher

unread,
Jun 20, 2011, 2:44:42 PM6/20/11
to validate...@googlegroups.com
On Mon, Jun 20, 2011 at 2:16 PM, Bob Silverberg
<bob.sil...@gmail.com> wrote:
> I wanted to bring this to the -dev list for discussion. The question
> is: Should VT ignore rules for properties that do not exist?
> Currently it does not ignore them - it throws an exception.  I can see
> how it could be useful for the FW to ignore missing properties in some
> cases, but I'm not sure if it's a good practice.
>
> If we do like the idea we could consider adding a config option to
> turn this feature on and off, but I'm also wary of adding more config
> options.
>
> What do folks think about this?

I have no opinion one way or the other, except to say that I like the
default behavior, and its presence has caused me to catch stupid bugs
earlier than I would have otherwise.

> You received this message because you are subscribed to the Google Groups "ValidateThis-dev" group.
> To post to this group, send email to validate...@googlegroups.com.
> To unsubscribe from this group, send email to validatethis-d...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/validatethis-dev?hl=en.
>
>

Matt Quackenbush

unread,
Jun 20, 2011, 2:49:53 PM6/20/11
to validate...@googlegroups.com
I'm with Marc.  Although I'll go one step farther and say that if the current behavior changed without the user specifically configuring it to do so, I'd be upset.  :-)

Jim Priest

unread,
Jun 20, 2011, 2:55:17 PM6/20/11
to validate...@googlegroups.com
My original need for this was a weird edge case for sure, mixed with a bit of laziness on my part.  

Thinking about it again I'm not sure if I'd vote for it - as you mention it has potential for abuse... and no one else is posting issues regarding this so your time is probably spent on something more important. 

Or course if I run into this again I'll want it implemented immediately :)

Jim

Bob Silverberg

unread,
Jun 20, 2011, 3:45:27 PM6/20/11
to validate...@googlegroups.com
Thanks everyone for your thoughtful responses. Less work for me! 

Sent from my iPhone

Mark Mandel

unread,
Jun 20, 2011, 9:18:21 PM6/20/11
to validate...@googlegroups.com
The only place  I can think this would be useful is for struct validation.

Basically, if the form scope is being validated, certain form values may not be present (much like it's client side counterpart), and it would be handy there if you could skip non-existing rules on the struct.

For an object, it would be pretty rare that 2 instances wouldn't have the same set of properties, so that seems less like it would be something people would actually need.

(Just throwing in my 2c)

Mark
E: mark....@gmail.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

cf.Objective(ANZ) - Nov 17, 18 - Melbourne Australia
http://www.cfobjective.com.au

Hands-on ColdFusion ORM Training
www.ColdFusionOrmTraining.com

Jamie Krug

unread,
Jun 21, 2011, 8:04:03 AM6/21/11
to validate...@googlegroups.com
Is this issue not handled with or without a required rule? I recall helping to work out an issue a while back where some rules implicitly assumed the property was also required, while others did not. I thought we cleaned it up, but I can't recall all details and I'm not able to peak at the code at this moment. But my thought would be that a numeric rule on a property but no required rule would pass quietly if the property does not exist; if it does exist, it would have to be numeric, but if it did not, then no failure or exception. If you added a required rule to that property, it would of course need to exist and match all other rules to pass.

John Whish

unread,
Jun 21, 2011, 8:15:26 AM6/21/11
to validate...@googlegroups.com
Bit late the party but...

I like the default behaviour where it throws an exception.

Regarding the PDF object, could you mixin an onMissingMethod method,
which would could handle missing properties? (Yes, this is a complete
stab in the dark!)

Bob Silverberg

unread,
Jun 21, 2011, 8:17:05 AM6/21/11
to validate...@googlegroups.com
I don't think that applies to this situation, Jamie.  What you say is correct, but only with an empty value, not an actual missing property.  A missing property is when the object (or more likely struct) being validated does not even support that property (i.e., there's no getter for it).  In that case the fw throws an exception.

Bob

Bob Silverberg

unread,
Jun 21, 2011, 8:18:42 AM6/21/11
to validate...@googlegroups.com
Valid points, Mark.  One case in which I could see people wanting this behaviour for objects (as opposed to structs) is when using inheritance.  One might want to have a set of rules that can be used for all of the subclasses, as opposed to a set of rules for each subclass, and that would be more easily facilitated by allowing for missing properties.

Bob

On Mon, Jun 20, 2011 at 9:18 PM, Mark Mandel <mark....@gmail.com> wrote:

Bob Silverberg

unread,
Jun 21, 2011, 8:21:27 AM6/21/11
to validate...@googlegroups.com
That would work to an extent, but the onMM would have to be smart enough to return a value that still passes the validation, otherwise even though you aren't getting exceptions you'd still get validation failures.

I'm actually starting to like Jim's original suggestion which was to add an argument to the validate() method (as opposed to a config flag). This would allow one to turn on this behaviour for specific operations, and it wouldn't be terribly complicated to implement.

What do folks think about making this an optional argument to the validate() method, with the default being the current behaviour?

Cheers,
Bob


--
You received this message because you are subscribed to the Google Groups "ValidateThis-dev" group.
To post to this group, send email to validate...@googlegroups.com.
To unsubscribe from this group, send email to validatethis-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/validatethis-dev?hl=en.

John Whish

unread,
Jun 21, 2011, 8:26:09 AM6/21/11
to validate...@googlegroups.com
> I'm actually starting to like Jim's original suggestion which was to add an
> argument to the validate() method (as opposed to a config flag).

I'd vote for that

Mark Mandel

unread,
Jun 21, 2011, 8:33:32 AM6/21/11
to validate...@googlegroups.com
Sounds good to me.

Mark


--
You received this message because you are subscribed to the Google Groups "ValidateThis-dev" group.
To post to this group, send email to validate...@googlegroups.com.
To unsubscribe from this group, send email to validatethis-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/validatethis-dev?hl=en.




--

Jamie Krug

unread,
Jun 21, 2011, 9:18:20 AM6/21/11
to validate...@googlegroups.com
Ditto: sounds good to me. (And thanks for earlier clarification, Bob, concerning empty value versus missing/null.)

Matt Quackenbush

unread,
Jun 21, 2011, 9:28:07 AM6/21/11
to validate...@googlegroups.com
Tritto.  (That's the new word for "me three!")

Bob Silverberg

unread,
Jun 25, 2011, 9:21:01 AM6/25/11
to validate...@googlegroups.com
Hey everyone,

In case you're interested, I have implemented this feature and pushed it to the develop branch at https://github.com/ValidateThis/ValidateThis.  Feel free to pull the latest changes and take it for a spin.

Cheers,
Bob
Reply all
Reply to author
Forward
0 new messages