These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Problem validating dates in LC w/Javascript

cl5792
Registered: Jul 17 2008
Posts: 53
Answered

I have a LC form (v8.0) with 2 date/time fields.

DateNow = calculated value for current date, formatted MM/DD/YY.
DateRequested = formatted mm/dd/yy with date control for selection.

I need to validate that the DateRequested is not before the DateNow. I have this script on the exit event for DateRequested:

----- Root.Page1.DateRequested::exit: - (JavaScript, client) ---------------------------------------

if (this.rawValue != null)
{
if (this.rawValue < DateNow.rawValue)
{
xfa.host.messageBox("Please check your Requested date. It cannot be before the current date!", "Date Checker", 3);
this.rawValue = null;
// to set focus to the DateRequested field so that the user can type his new value..
xfa.host.setFocus(this.somExpression);
}
}

The problem is that the rawValue for DateNow is returning "12/4/08" but the rawValue for RequestedDate is returning "2008-12-01" and it does not validate as being prior to the current date (DateNow). What am I missing?

Thank you for any assistance provided.

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
I find dealing with the formatted value can provide a more controlled result for date strings, but if you want to compare dates it is always better to convert the date time strings to a number since it reduces all variations of date strings to the same value.

George Kaiser

cl5792
Registered: Jul 17 2008
Posts: 53
Thank you for responding. Can you provide any assistance on getting the numeric value of a date/time field using Livecycle JavaScript?
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
For your situation, I would use the "Validate" script option with the following code:

// see current date is less than requested date - display format "YYYY-MM-DD"
Date() < Date2Num($.formattedValue, "YYYY-MM-DD")And the following "Validation script error":

Please check your Requested date. It cannot be before the current date!

George Kaiser

cl5792
Registered: Jul 17 2008
Posts: 53
I get the following error in the validation event:

Date2Num is not defined
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
The script is for LiveCycle Designer FormCalc.

George Kaiser

cl5792
Registered: Jul 17 2008
Posts: 53
I need to validate against the value of the calculated field DateNow. This should work boes does not. Help?

Date2Num(xfa.form.Root.Page1.DateNow.formattedValue, "mm/dd/yy") <= Date2Num($.formattedValue, "mm/dd/yy")
cl5792
Registered: Jul 17 2008
Posts: 53
I was able to get this to work:

Date2Num($.formattedValue, "MM/DD/YY") >= Date2Num(xfa.form.Root.Page1.DateNow[0].formattedValue, "MM/DD/YY")Apparently I needed to have the format in upper case.

thank you for your assistance.