I have a field in a form set as date. I am trying to validate the date entered, has to actually be a date AND equal or after today, if not stay on the field until it is corrected.
Solved! Go to Solution.
Views
Replies
Total Likes
Use FormCalc for this it is easier to do date arithmetic in that language. You would do this on the exit event of the field (that way the user has already chosen a date). There is a function called (Date2Num) that will take the date passed to it and convert it to the number of days that have elapsed from a specific time (called an epoch). So you woudl have to het todays number then get the number of the date the user chose and do a simple test to see if todays number is greater than the current one. Something like this:
//get the number for the selected date
var selectedNum = Date2Num($.rawValue, "YYYY-MM-DD")
//the Date() function returns the number of days from the epoch for the current date (system time)
if ( selectedNum <= Date()) then
//its earlier ..let the user know
xfa.host.messageBox("Please enter a date later than todays date!")
// put the cursor back in the Date selection field
xfa.host.setFocus("DateTimeField1")
endif
This assumes that your Date selection field is called DateTimeField1
Paul
Views
Replies
Total Likes
Use FormCalc for this it is easier to do date arithmetic in that language. You would do this on the exit event of the field (that way the user has already chosen a date). There is a function called (Date2Num) that will take the date passed to it and convert it to the number of days that have elapsed from a specific time (called an epoch). So you woudl have to het todays number then get the number of the date the user chose and do a simple test to see if todays number is greater than the current one. Something like this:
//get the number for the selected date
var selectedNum = Date2Num($.rawValue, "YYYY-MM-DD")
//the Date() function returns the number of days from the epoch for the current date (system time)
if ( selectedNum <= Date()) then
//its earlier ..let the user know
xfa.host.messageBox("Please enter a date later than todays date!")
// put the cursor back in the Date selection field
xfa.host.setFocus("DateTimeField1")
endif
This assumes that your Date selection field is called DateTimeField1
Paul
Views
Replies
Total Likes
You can use FormCalc for this purpose.
This script in the exit:Event will warn the users, if the date is before todays date.
Oh, Paul was faster than me
Thanks guys!
Is there really a difference in using javascript vs FormCalc?
Views
Replies
Total Likes
You will get to the same place ....doing date calculations in Javascript will require more statements than what you see in FormCalc...so I gies it comes down to a matter of preference.
Paul
Views
Replies
Total Likes
Hello Everyone,
I know this is really late, but I don't get a warning if I pick an earlier date. What could I be doing in correctly? I literally copied and pasted. If your code still valid for 2017's pro version?
Thanks.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies