Skip to main content
Inspiring
May 7, 2024
Question

How can we block months in the calendar in date fields ?

  • May 7, 2024
  • 1 reply
  • 541 views

Hi, I have a pdf form in which I have two dates fields side by side. I would like to know if we can block some months in the calendar so people cannot choose these dates in the first date field. In the second field there is already this custom calculation script :

 

var cDate = this.getField("DateField3").value;
if (cDate) {
var d1 = new Date();
d1 = util.scand("dd/mm/yyyy", cDate);
d1.setDate(d1.getDate() - 1) + d1.setFullYear(d1.getFullYear() + Number(this.getField("Dropdown44").valueAsString));
event.value = util.printd("dd/mm/yyyy", d1);
}

 

It's not related but I guess it add a specificity to the code for the first box to block months in the calendar. What is the code for this ?

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
May 7, 2024

You can't block out months in the calendar widget, but you can use a validation script to reject certain values, which will cause the field to revert to its previous value.

Here's an example of how to reject any dates between June and August (notice the month numbers are zero-based):

 

if (event.value) {
	var d = util.scand("mm/dd/yyyy", d);
	if (d.getMonth()>=5 && d.getMonth()<=7) {
		app.alert("You may not select a date in June, July or August.",1);
		event.rc = false;
	}
}

PS. You should post your questions in the Acrobat forum, not the Reader one.

Inspiring
May 7, 2024

Oh ok, I will next time. Unfortunately, it doesn't seem to work.

try67
Community Expert
Community Expert
May 7, 2024

What do you mean, "next time"? What did you try, and what were the results?