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

Need to validate second date

New Here ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

Hello,

 

I am creating a fillable PDF form using Adobe Acrobat DC. There are two fields that requires the person to select dates - Start and End date. How can we have the End date check to make sure that it is AFTER the Start date? Please see attachment for screen capture.

TOPICS
Create PDFs , JavaScript , PDF forms

Views

754

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 , Mar 22, 2021 Mar 22, 2021

You will have to write a custom validation script for the end date field. Something like this shoud work (not tested, so there might be errors):

 

var retVal = true;
// get information from "Date1"
var d1 = this.getField("Date1_af_date").value;
if (d1 == "") {
    app.alert("Start date is empty");
    retVal = false;
}
if (retVal && event.value == "") {
    app.alert("End date is empty");
    retVal = false;
}
if (retVal) {
    var d1 = new Date(d1);
    var d2 = new Date(event.value);
    if (d
...

Votes

Translate

Translate
Community Expert ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

You will have to write a custom validation script for the end date field. Something like this shoud work (not tested, so there might be errors):

 

var retVal = true;
// get information from "Date1"
var d1 = this.getField("Date1_af_date").value;
if (d1 == "") {
    app.alert("Start date is empty");
    retVal = false;
}
if (retVal && event.value == "") {
    app.alert("End date is empty");
    retVal = false;
}
if (retVal) {
    var d1 = new Date(d1);
    var d2 = new Date(event.value);
    if (d1 > d2) {
        app.alert("End date needs to be after start date");
        retVal = false;
    }
}
event.rc = retVal;

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
New Here ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

Thanks Karl! It works!

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
New Here ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

Hi Karl, [total newbie] almost the same request, but need a custom validation script for a fillable form that allows the user to only select a future date 30 days from today's date. Thanks in advance—Rudy

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
Community Expert ,
Jul 27, 2022 Jul 27, 2022

Copy link to clipboard

Copied

LATEST

Rudy, please post a new question.

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