Skip to main content
Inspiring
May 8, 2024
Answered

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

  • May 8, 2024
  • 1 reply
  • 705 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.
Correct answer Nesa Nurani

Let's say you want to 'block' 5th and 6th months (May, June), use this as 'Validate' script of that field:

var dateStr = event.value;
if (dateStr) {
var dateParts = dateStr.split("/");
var month = parseInt(dateParts[1], 10);

if (month === 5 || month === 6) {
app.alert("Dates in May and June are not allowed.");
event.rc = false;}}

This will work for format "dd/mm/yyyy".

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
May 8, 2024

Let's say you want to 'block' 5th and 6th months (May, June), use this as 'Validate' script of that field:

var dateStr = event.value;
if (dateStr) {
var dateParts = dateStr.split("/");
var month = parseInt(dateParts[1], 10);

if (month === 5 || month === 6) {
app.alert("Dates in May and June are not allowed.");
event.rc = false;}}

This will work for format "dd/mm/yyyy".

Inspiring
May 8, 2024

Thank you, it works perfectly.