multi-conditionals

38 views
Skip to first unread message

Mark Kiel

unread,
Sep 26, 2013, 2:38:42 PM9/26/13
to valida...@googlegroups.com
First... Love ValidateThis... excellent product and exactly what I needed for this project.

I am trying to validate that an  end date is required only if a start date has been entered. 

<property name="BenefitClassEndDate" desc="Benefit Class End Date">
<rule type="required">
<param name="DependentPropertyName" value="BenefitClassStartDate" />
</rule>
<rule type="Regex" failureMessage="Dates should use the correct format (M/D/YYYY)">
<param name="regex" value="[0-9]?[0-9]/[0-9]?[0-9]/[0-9][0-9][0-9][0-9]" />
</rule>
<rule type="noHTML" />
</property>

Now I need to also make sure the end date is AFTER the start date. I wrote the conditional,

<condition name="BenefitClassDateCheck"
serverTest="DateCompare( BenefitClassStartDate, BenefitClassEndDate, 'd' ) eq -1"
clientTest="(new Date($('[name=BenefitClassStartDate]').getValue()) - new Date($('[name=BenefitClassEndDate]').getValue())) >0;" />

I'm just not sure how to implement it...

John Whish

unread,
Sep 26, 2013, 2:45:03 PM9/26/13
to valida...@googlegroups.com


--
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/groups/opt_out.

John Whish

unread,
Sep 26, 2013, 2:50:45 PM9/26/13
to valida...@googlegroups.com
Hi Mark,

When I need custom validation I just create a new Validators. Have a read of this:
On 26 September 2013 19:38, Mark Kiel <marcu...@gmail.com> wrote:

Mark Kiel

unread,
Sep 27, 2013, 4:24:37 PM9/27/13
to valida...@googlegroups.com, john....@googlemail.com
Thats a great help. Seems pretty basic to add validation like I need. 

How do I write the property so that it passes the both the dates (date_a, and date_b). I can write the compare statement very easily, just not sure how to pass in both variables.
Message has been deleted

Mark Kiel

unread,
Sep 30, 2013, 11:40:35 AM9/30/13
to valida...@googlegroups.com
Success... 

<cfscript>
var otherPropertyName = arguments.validation.getParameterValue("ComparePropertyName");
var otherVal = arguments.validation.getObjectValue(otherPropertyName);
var args = [arguments.validation.getPropertyDesc(),otherVal];
var msgKey = "defaultMessage_compare2dates";
</cfscript>
        
<cfif dateCompare( arguments.validation.getObjectValue(), otherVal ) lte 0 >
<cfset fail(arguments.validation,variables.messageHelper.getGeneratedFailureMessage(msgKey,args,arguments.locale)) />
</cfif>

<rule type="compare2dates" failureMessage="New Hire Begin Date must be before New Hire End Date.">
<param name="ComparePropertyName" value="NewHireBegin" />
</rule>

John Whish

unread,
Sep 30, 2013, 6:01:28 PM9/30/13
to valida...@googlegroups.com

Glass you got it working!

--

John Whish

unread,
Sep 30, 2013, 6:03:27 PM9/30/13
to valida...@googlegroups.com

Oops, that was supposed to be "glad".

Samsung's Swipe keyboard is great 99% of the time... :-)

Reply all
Reply to author
Forward
0 new messages