I would like a date field where the user must enter a date that is at least 1,095 days (3 years) prior to todays date.
Solved! Go to Solution.
Views
Replies
Total Likes
Yes, you variable dateToday doesnt need to have the function Date2Num, as I said, Date() returns the same value as Date2Num would
Views
Replies
Total Likes
Using FormCalc, you can use the function Date2Num() and have the following algorithm:
var dateEntered = Date2Num(dateField.rawValue, "YYYY-MM-DD")
var dateToday = Date2Num(date(), "YYYY-MM-DD")
if (dateEntered gt dateToday - 1095) then
//code here
endif
Views
Replies
Total Likes
Thanks for your reply
I entered what you sent me as an exit event but I get a script error. I am assuming that is because I have not told it what I want it to do so,
How do I tell it to clear whatever incorrect date was entered and then display a message similar to "Sorry that is not a valid Date of Birth for this Form"
form1.#subform[0].ClientInfo1.DateOfBirth::exit - (FormCalc, client)
var dateEntered = Date2Num(dateField.rawValue, "YYYY-MM-DD")
var dateToday = Date2Num(date(), "YYYY-MM-DD")
if (dateEntered gt dateToday - 1095) then
//code here
endif
Views
Replies
Total Likes
The error occured because there was no code inside the "if" brackets where I wrote //code here.....
and secondly, if you don't change dateField you will have another error... Choose either "this" or "DateOfBirth"
and third (srry about this one) Date() already returns a Number, no need to use Date2Num
var dateEntered = Date2Num(this.rawValue, "YYYY-MM-DD")
var dateToday = Date()
if (dateEntered gt dateToday - 1095) then
xfa.host.messageBox("Sorry that is not a valid Date of Birth for this Form.", "Validaton Failed", 0)
endif
Views
Replies
Total Likes
First,
Thank you for your time, it is much appreciated.
I have entered the code as you have suggested, but I get the messagebox no mater what date I enter. Is there something else that I am missing here?
form1.#subform[0].ClientInfo1.DateOfBirth::exit - (FormCalc, client)
var dateEntered = Date2Num(DateOfBirth.rawValue, "YYYY-MM-DD")
var dateToday = Date2Num(date(), "YYYY-MM-DD")
if (dateEntered gt dateToday - 1095) then
xfa.host.messageBox("Sorry that is not a valid Date of Birth for this Form.", "Validaton Failed", 0)
endif
Views
Replies
Total Likes
Yes, you variable dateToday doesnt need to have the function Date2Num, as I said, Date() returns the same value as Date2Num would
Views
Replies
Total Likes
My apologies. Somehow I missed that bit about Date().
Things are now functioning as I had hoped,
Just wanted to take a moment to say thankyou. It is the willingness of people like you give of your time and knowledge that make these things possible for people like me that might only have to create the occasional form.
Views
Replies
Total Likes
Hi,
when you check dates or times, you better grab the formattedValue instead of the rawValue, as they can be different when you did not provide a data pattern.
form1.#subform[0].ClientInfo1.DateOfBirth::exit - (FormCalc, client)
var dateEntered = Date2Num($.formattedValue, "YYYY-MM-DD")
if (dateEntered gt Date() - 1095) then
xfa.host.messageBox("Sorry that is not a valid Date of Birth for this Form.", "Validaton Failed", 0)
endif
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies