Copier le lien dans le Presse-papiers
Copié
Copier le lien dans le Presse-papiers
Copié
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"]);
}
}
Copier le lien dans le Presse-papiers
Copié
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?
Copier le lien dans le Presse-papiers
Copié
Unfortunately no, these fields have to be individual, can you help?
Copier le lien dans le Presse-papiers
Copié
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"]);
}
}
Copier le lien dans le Presse-papiers
Copié
This is incredible! Thank you so much! It works!
Copier le lien dans le Presse-papiers
Copié
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:
Copier le lien dans le Presse-papiers
Copié
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.
Copier le lien dans le Presse-papiers
Copié
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?
Copier le lien dans le Presse-papiers
Copié
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;}}}
Copier le lien dans le Presse-papiers
Copié
Works like a charm, thank you very much Nesa.
Copier le lien dans le Presse-papiers
Copié
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)
Trouvez plus d’idées, d’événements et de ressources dans la nouvelle communauté Adobe
Explorer maintenant