Copy link to clipboard
Copied
Copy link to clipboard
Copied
You can use this code as the custom calculation script of a (hidden) text field:
var startDateMonth = this.getField("part3.month").valueAsString;
var startDateDay = this.getField("part3.day1").valueAsString;
var startDateYear = this.getField("part3.year").valueAsString;
var endDateMonth = this.getField("part3b.month").valueAsString;
var endDateDay = this.getField("part3b.day1").valueAsString;
var endDateYear = this.getField("part3b.year").valueAsString;
if (startDateMonth && startDateDay && startDateYear && endDateMonth && endDateDay && endDateYear) {
var startDate = util.scand("mmm dd yyyy", startDateMonth + " " + startDateDay + " "+ startDateYear);
var endDate = util.scand("mmm dd yyyy", endDateMonth + " " + endDateDay + " "+ endDateYear);
if (startDate && endDate && startDate.getTime()>=endDate.getTime()) {
app.alert("Error! The end date must be after the start date.");
this.resetForm(["part3b.month", "part3b.day1", "part3b.year"]);
}
}
Copy link to clipboard
Copied
This is a bit complicated to do with individual fields for month, day and year, as you would first need to validate that all the fields are filled-in, before merging them into a single string, then converting that string into a Date object and compared it with the Date object from the other field.
Can you combine them to a single field, you think?
Copy link to clipboard
Copied
Unfortunately no, these fields have to be individual, can you help?
Copy link to clipboard
Copied
You can use this code as the custom calculation script of a (hidden) text field:
var startDateMonth = this.getField("part3.month").valueAsString;
var startDateDay = this.getField("part3.day1").valueAsString;
var startDateYear = this.getField("part3.year").valueAsString;
var endDateMonth = this.getField("part3b.month").valueAsString;
var endDateDay = this.getField("part3b.day1").valueAsString;
var endDateYear = this.getField("part3b.year").valueAsString;
if (startDateMonth && startDateDay && startDateYear && endDateMonth && endDateDay && endDateYear) {
var startDate = util.scand("mmm dd yyyy", startDateMonth + " " + startDateDay + " "+ startDateYear);
var endDate = util.scand("mmm dd yyyy", endDateMonth + " " + endDateDay + " "+ endDateYear);
if (startDate && endDate && startDate.getTime()>=endDate.getTime()) {
app.alert("Error! The end date must be after the start date.");
this.resetForm(["part3b.month", "part3b.day1", "part3b.year"]);
}
}
Copy link to clipboard
Copied
This is incredible! Thank you so much! It works!
Copy link to clipboard
Copied
I have a similar issue but im my case I also need to be able to select the same day as well but for some reason its not working:
Copy link to clipboard
Copied
If you want to allow same day, you need to check that end date is strictly larger (>) not (>=).
Since you use getTime() and since you probably won't select both fields within same second end date will always be larger, when you get dates set both dates to same time.
Copy link to clipboard
Copied
Thank you Nesa for clarifying, it worked but I still get the alert I set up and have to click on it 3 more times before it works fine, is it because of the getTime?
Copy link to clipboard
Copied
It's probably your script, try this:
if (event.value) {
var startDateString = this.getField("Date1_af_date").valueAsString;
if (startDateString=="") {
app.alert("Please complete the header date first.");
event.rc = false;}
else {
var startDate = util.scand("mm/dd/yyyy", startDateString);
var endDate = util.scand("mm/dd/yyyy", event.value);
startDate.setHours(0, 0, 0, 0);
endDate.setHours(0, 0, 0, 0);
if (endDate.getTime() > startDate.getTime()) {
app.alert("The date of this inspection cannot be after the completion of this form date.");
event.rc = false;}}}
Copy link to clipboard
Copied
Works like a charm, thank you very much Nesa.
Copy link to clipboard
Copied
I have a similar issue but im my case I also need to be able to select the same day and as well but for some reason its not working: (so its previous dates and same day but not after the header date)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now