Am I doing this right?

24 views
Skip to first unread message

Dean.Lawrence

unread,
Dec 19, 2011, 10:55:00 AM12/19/11
to ValidateThis
I have a client form that has password and confirm password fields on
it. If this is a new client, both fields are required, must be a
certain number of characters, and must match. If I am editing a
client, both fields are optional, but if you enter something into
either one, they again must match and be a certain number of
characters. I have this working when I use an external xml rule file.


<?xml version="1.0" encoding="UTF-8"?>
<validateThis xsi:noNamespaceSchemaLocation="http://
www.validatethis.org/validateThis.xsd" xmlns:xsi="http://www.w3.org/
2001/XMLSchema-instance">
<contexts>
<context name="Add" formName="frmEdit" />
<context name="Edit" formName="frmEdit" />
</contexts>
<objectProperties>
<property name="clientName" desc="Client Name">
<rule type="required" contexts="*" />
</property>
<property name="clientPassword" desc="Password">
<rule type="required" contexts="Add" />
<rule type="rangelength" contexts="*">
<param name="minlength" value="5" />
<param name="maxlength" value="100" />
</rule>
</property>
<property name="VerifyPassword">
<rule type="required" contexts="Add" />
<rule type="equalTo" contexts="*">
<param name="ComparePropertyName" value="clientPassword" />
</rule>
</property>
</objectProperties>
</validateThis>

However, if I try to move the rules into the component itself, if I
edit a client and do not enter anything into the password field, I get
an error that "The Password must be between 5 and 10 characters long."
Here is my component.

component displayname="Client" output="false" persistent="true"
table="tblClient" extends="BaseORMService" {
property name="clientID" type="numeric" fieldtype="id"
generator="native";
property name="clientName" displayName="Client Name" type="string"
vtRules='[
{"type":"required","contexts":"*"}
]';
property name="clientPassword" displayName="Password" type="string"
vtRules='[
{"type":"required","contexts":"Add"},
{"type":"rangelength","contexts":"*",
"params":[
{"name":"minlength","value":"5"},
{"name":"maxlength","value":"10"}
]
}
]';
property name="address" type="string";
property name="address2" type="string";
property name="city" type="string";
property name="state" type="string";
property name="postalCode" type="string";
property name="phone" type="string";
property name="contactName" type="string";
property name="contactEmail" type="string";
property name="deals" type="array" fieldtype="one-to-many" cfc="Deal"
singularname="deal" fkcolumn="clientID" inverse="true" cascade="all-
delete-orphan";
property name="dteCreated" type="string" ormtype="timestamp";
property name="dteModified" type="string" ormtype="timestamp";

property name="verifyPassword" type="string" persistent="false"
vtRules='[
{"type":"required","contexts":"Add"},
{"type":"equalTo","contexts":"*",
"params" : [
{"name":"ComparePropertyName","value":"clientPassword"}
]
}
]';
}


Am I just coding my component wrong or is this a bug?

Thanks,

Dean

Bob Silverberg

unread,
Dec 19, 2011, 11:13:17 AM12/19/11
to valida...@googlegroups.com
If it's working with the xml file then I agree that either you've done
something wrong with your json or there's a bug in the internal
conversion from json. I have never used the json format, so I'm not
sure. Maybe someone who does use the json format can take a look at
this?

In the meantime, can you do the following?

On the page that processes the form, where you'd normally call:

result = validateThis.validate(object);

can you instead do this:

contexts = validateThis.getAllContexts(object);

and then dump the contents of contexts and show us what it holds?

Thanks,
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

Dean.Lawrence

unread,
Dec 19, 2011, 11:47:06 AM12/19/11
to ValidateThis
Thanks Bob,

I did a dump of both rule methods and compared them and they were both
identical except for the max password value. The xml version was set
to 100 (the actual db field length) and the annotation version was set
at 10. I realized that I am encrypting the password which is making
the string longer than 10 characters, which would explain why
ValidateThis was throwing a failed validation. So it appears that it
is working properly and it was indeed my fault.

Thanks for pointing in the right direction.

Dean

Reply all
Reply to author
Forward
0 new messages