• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
4

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

Explorer ,
May 08, 2024 May 08, 2024

Copy link to clipboard

Copied

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 ?

TOPICS
How to , JavaScript , PDF forms

Views

185

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 08, 2024 May 08, 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".

Votes

Translate

Translate
Community Expert ,
May 08, 2024 May 08, 2024

Copy link to clipboard

Copied

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".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 08, 2024 May 08, 2024

Copy link to clipboard

Copied

LATEST

Thank you, it works perfectly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines