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

Complex Date Validation - how to? Restrict to day of week and range

lokidog
Registered: Apr 10 2008
Posts: 12

I want to force users to choose a date that is within a range of dates and is only on a saturday.

How do I do this?

The date range should be from May till October and only Saturdays.

Thanks.

I can't even figure out what the syntax would be - and whether I can use the validation event or need to use the exit event. I could probably figure this out from other examples, but all that I've found are missing the information I need to program this in JS or Formcalc.

Thanks.

My Product Information:
LiveCycle Designer, Windows
lokidog
Registered: Apr 10 2008
Posts: 12
Further information:

So I need to figure out how to reference today's date - I think it's something like this: var Todaysdate = new Date();

Then I need to restrict the entered date (entereddate) to be

entereddate >= Todaysdate
AND
Day of the Week of (entereddate) to = Saturday
AND
entereddate <= than the the End Date in OctoberThen if this is all true - allow the entered date to stand, otherwise go back to reenter the date.

then I need the way to frame this in the Validation or Exit Event Procedure.

I've worked with the Click Procedure to enter data based on a checkbox, so I'm not completely unfamiliar with JS, I just need a little nudge in the right direction for this.
lokidog
Registered: Apr 10 2008
Posts: 12
Got some of it - never found adequate JS script syntax but in formcalc


// This results in the day of the week of the entered date $
var test = Num2Date(Date2Num($.rawValue, "YYYY-MM-DD"), "E")
Test1.rawValue = test ; This displays the Day of Week in a text box named test1
// Tests to see if Date is in the future, before closing date, and a saturday
Date2Num($.rawValue, "YYYY-MM-DD") >= Date()& Date2Num($.rawValue, "YYYY-MM-DD") <= Date2Num("Oct 4, 2008")// These two lines would be part of above lines, but result in errors
// & Num2Date(Date2Num($.rawValue, "YYYY-MM-DD"), "E") = "7"
// & test = 7//Date2Num($.rawValue, "YYYY-MM-DD") >= Date() test to see if date is today or in future
//Date2Num($.rawValue, "YYYY-MM-DD") <= Date2Num("Oct 4, 2008") tests to see if date is before closing dateSo how do I put in the Day of Week test. Day of week displays correctly in the textbox named Test1 - 1=Sunday, 7=Saturday.

I've tried various formate - EEEE makes the day of week the full name, etc.

Help!
lokidog
Registered: Apr 10 2008
Posts: 12
Sorry - Reposted as Code - This is what I have now and it works so far - just need to get the day of week to be validated in a statement - it's all syntax - but the reference says nothing about it - at least explicitly.

// This results in the day of the week of the entered date $var test = Num2Date(Date2Num($.rawValue, "YYYY-MM-DD"), "E")Test1.rawValue = test ; This displays the Day of Week in a text box named test1// Tests to see if Date is in the future, before closing date, and a saturdayDate2Num($.rawValue, "YYYY-MM-DD") >= Date()& Date2Num($.rawValue, "YYYY-MM-DD") <= Date2Num("Oct 4, 2008") // These two lines would be part of above lines, but result in errors// & Num2Date(Date2Num($.rawValue, "YYYY-MM-DD"), "E") = "7"// & test = 7 //Date2Num($.rawValue, "YYYY-MM-DD") >= Date() test to see if date is today or in future//Date2Num($.rawValue, "YYYY-MM-DD") <= Date2Num("Oct 4, 2008") tests to see if date is before closing date
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
To get the level of granularity you need it may be simpler to use the JavaScript date functions. You'll find these listed in any Core JavaScript Reference. For example, there is a Data.getDay() function that returns the day of the week.

Here's an article on using Dates and Times in AcroForms, but most of the article is on Dates in Core JS, which is also applicable to LiveCycle scripting.

http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/date_time_part1/

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

lokidog
Registered: Apr 10 2008
Posts: 12
Already tried this and it was no help. I went through the article extensively and used the console in Acrobat, but when trying out the code it Livecylce all I got were errors. It also does not have the getday info (I did find this in the JS references I downloaded). But then I am lost on finding out how to get the milisecond format from the date entered - Please post and example that WORKS in Livecycle - somthing like JAVADATE(this.RawValue) or something like this.

So unless I have an example to work from in the validation portion of Livecycle I can't use JS. - For example the 'util' function has no meaning in Livecycle - at least when I tried it.

I looked at JS references - anybody can - but it's like looking at a dictionary and trying to write a sentence. I need more help with this particular example than this.

As I said - I'm getting everything I need except day of the week with Formcalc- but something is missing in the function and I have no idea what that could be. I prefer JS but I have had no luck.

Please give an example in JS code that actually works here. All I probaly need is a way to get the numerical date info out of the date entered in Livecyle. From there I can figure out the methods, etc. in JS that will work on this.
lokidog
Registered: Apr 10 2008
Posts: 12
I'm now trying to use JS as I've not received an answer about the glitch in formcalc.

I put a simple set of statements together:

code
var testa = this.rawValue.replace("-",",","g");
//var testb = testa.slice(2); - I thought maybe I needed it in this format - but no
var testc = new Date(testa);
var testd = testc.toString();
Test1.rawValue = testa;
Test2.rawValue = testd;
/code

I get on textbox - to show what I'd like - "2008,04,26" if that was what was chosen.

However when I try to convert the variable testa - which = "2008,04,26"
in the new Date(testa) statement - and show it - it comes up invalid.

I searched but found nothing. Seems it should work and show JS date. Maybe I'm leaving out some little character or coding?

code
var testc new Date (2008,04,26)
/code

works - although this forces a falure of the validation - I'll work on this later.
crisis_davis
Registered: Apr 14 2008
Posts: 3
try this:


function valididateDate(yourDate, startDate,endDate,dayOfWeek) {
console.println (yourDate.rawValue + " " + startDate.rawValue + " " + endDate.rawValue + " " + dayOfWeek.rawValue);

//convert text dates into date objects
var start = util.scand("yyyy/mm/dd",startDate.rawValue);
var end = util.scand("yyyy/mm/dd",endDate.rawValue);
var yours = util.scand("yyyy/mm/dd",yourDate.rawValue);
console.println (start + "\n" + end + "\n" + yours + "\n your day : " + yours.getDay());

//check that the dates are valid dates based on the format specified (yyyy/mm/dd)
if (start == null || end == null || yours == null)
app.alert ("date(s) not valid - must be in yyyy/mm/dd format");
else
//check the range and the day of the week
if (yours > end || yours < start || yours.getDay() != dayOfWeek.rawValue -1)
app.alert ("date out of range");
else
app.alert ("date just fine");
}
lokidog
Registered: Apr 10 2008
Posts: 12
Thanks much. Maybe I'm an idiot, but 'where' do I put this code?

In the validation event? In the underlying form code?

Thanks.