AddRule Rangelength

40 views
Skip to first unread message

Han

unread,
May 11, 2012, 1:49:29 PM5/11/12
to ValidateThis
Hi all,

I'm trying to add and rule to validate dynamic fields and have only
been able to get it to work for valType="required" or any other rule
that doesn't require parameters.

Does anyone have some sample code for validating with parameters?

Thanks,
Han

Bob Silverberg

unread,
May 11, 2012, 4:16:35 PM5/11/12
to valida...@googlegroups.com
You should be able to pass a struct of parameters into the addRule
method as an argument. For example:

params = {minLength=5, maxLength=10};
addRule(propertyName="userName", valType="rangeLength", parameters=params);

Bob
> --
> 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

Han Ah-Sue

unread,
May 11, 2012, 4:39:12 PM5/11/12
to valida...@googlegroups.com
Yeah, I tried that. For some reason I keep getting this error:

Element INSTANCE.TYPE is undefined in VARIABLES.

Bob Silverberg

unread,
May 11, 2012, 4:46:54 PM5/11/12
to valida...@googlegroups.com
You'll need to provide more detail than that for anyone to be able to
help you. Please provide the full stack trace, and also a snippet of
code that shows how you are calling the method.

Bob

Han

unread,
May 11, 2012, 5:52:09 PM5/11/12
to valida...@googlegroups.com
Here's my code....

imageCaption_183 is a dynamic field, I just removed the loop so it's a little bit easier to read.

I also have a try/catch around the whole block to trap system errors.


             <!--- this works great ---> 
             <cfset application.vt.AddRule(
                            objectType="content-image",
                            propertyName="imageCaption_183",
                            formName="imageCaption_183",
                            propertyDesc="Image Caption",
                            valType="required") />
            <!--- this throws an error --->
            <cfset var params = { minLength=5, maxLength=10 } />
            <cfset application.vt.AddRule( theObject=arguments,
                            objectType="content-image",
                            propertyName="imageCaption_183",
                            formName="imageCaption_183",
                            propertyDesc="Image Caption",
                            valType="rangeLength",
                            parameters=params ) />
                                   
            <!--- validate --->
            <cfset result = application.vt.validate( theObject=arguments, objectType="content-image" ) />
            <cfset status = result.getIsSuccess() />
            <cfif ! status>
                <cfset toReturn.status = status />
                <cfset toReturn.error = result.getFailureMessagesByField() />
            <cfelse>
                <!--- save image --->
                ...
            </cfif>
>> > validatethis+unsubscribe@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/validatethis?hl=en.
>> >
>>
>>
>>
>> --
>> Bob Silverberg
>> www.silverwareconsulting.com
>>
>> --
>> 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+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/validatethis?hl=en.
>>
>
> --
> 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+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages