Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Date Validation Script Help

Avatar

Level 1

Hello

I am creating a travel form on adobe designer 7.0 for employees to fill out before they go on vacation.  So i wrote a script that makes sure the the date entered for DateFrom is >= the current date and the DateTo is >= DateFrom.  I have been told to make the date format MM/DD/YY but for some reason the script only works when the format is MM/DD/YYYY.

Here is my script For DateFrom:

if (Date() < Date2Num($.formattedValue, "MM/DD/YYYY"))

then

xfa.host.setFocus("xfa.form.form1.DateTo")

else

xfa.host.setFocus("xfa.form.form1.DateFrom")
xfa.host.messageBox("Your requested date can NOT come before the current date","Warning.",1)

endif

and the script for DateTo:

if (Date2Num($.formattedValue, "MM/DD/YYYY") >= Date2Num(xfa.form.form1.DateFrom.formattedValue, "MM/DD/YYYY"))

then

xfa.host.setFocus("xfa.form.form1.enterC")

else

xfa.host.messageBox("The 'TO' Date must come after the 'FROM' Date", "TO DATE ERROR")
xfa.host.setFocus("xfa.form.form1.DateTo")

endif

enterC is the next focus object after DateTo

I have tried the obvious by switching the formattedValue to "MM/DD/YY" but with no success.  I have also tried switching the Display Pattern, Validation Pattern, and the Data Pattern to "MM/DD/YY" but nothing seems to work.  Does anyone know how to make this work with MM/DD/YY?

Thanks in advance for any help

Nick

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Idea is to keep the display format separate from the scripting format. You can use any format that you like in Display format and will not interfere with the script. In the script I would always like to use "YYYY-MM-DD" the international format which you do not have to worry about as long as you set the Display and Edit formats as you like.

View solution in original post

4 Replies

Avatar

Former Community Member

Irrespective of the display pattern/format I would use the following FormCalc code in your situation. Also check the attachment.

'exit' event of the DateFrom:

if (Date() <= Date2Num($.rawValue, "YYYY-MM-DD")) then
//xfa.host.setFocus("xfa.form.form1.DateTo")
var v1
v1=1
else
xfa.host.setFocus("xfa.form.form1.DateFrom")
xfa.host.messageBox("Your requested date can NOT come before the current date","Warning.",1)
endif

'exit' event of the DateTo

if (Date2Num($.rawValue, "YYYY-MM-DD") > Date2Num(xfa.form.form1.DateFrom.rawValue, "YYYY-MM-DD")) then
//xfa.host.setFocus("xfa.form.form1.enterC")
var v1
v1 =1
else
xfa.host.messageBox("The 'TO' Date must come after the 'FROM' Date", "TO DATE ERROR")
xfa.host.setFocus("xfa.form.form1.DateTo")
endif

Avatar

Level 1

Thank you very much for the help.  It works great but the fromat is slightly different.  I'm guessing that only certain formats can be used in date fields, so that 'MM/DD/YY' is just not compatible with Designer?  If that is the case then your script would be the answer I was looking for.  If that is not the case, could i just substitute 'MM/DD/YY' in for the 'YYYY-MM-DD'? or would that not work?

thanks again for the help

Nick

Avatar

Correct answer by
Former Community Member

Idea is to keep the display format separate from the scripting format. You can use any format that you like in Display format and will not interfere with the script. In the script I would always like to use "YYYY-MM-DD" the international format which you do not have to worry about as long as you set the Display and Edit formats as you like.

Avatar

Level 1

Oh ok I did not know that is how it worked.  Thank you very much!!!!!

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----