CONFIRM SEQUENTIAL DATE ENTRIES

Community Beginner ,
Feb 25, 2019

Copy link to clipboard

Copied

I am attaching an image of a portion of a log page. As you see, there are multiple (six) identical records - each has a date field.

I need to do two things: 1) Assure that the date being entered does not predate the date field in the previous record, and 2)

verify that there is indeed a date in the date field of the previous record (avoid skipping records). Here is some code I have tried, but I cannot get the if condition to work:

Please share your thoughts.

//THIS VALIDATES THE DATE ENTERED

var cMsg = "The date you entered is invalid.\n\nPlease enter a date that does not pre-date the previous entry date.";

var nIcon = 0;

var nType = 0;

var cTitle = "DATE ERROR";

var str = event.target.name;

var res = str.charAt(str.length-1);

var d1 = Date.parse(this.getField("0." + (res-1)).value);

var d2 = Date.parse(event.value);

if (d1 == 0) {

if (d1 > d2) {

app.beep();

app.alert(cMsg, nIcon, nType, cTitle);

event.value = "";

}

} else {

var cMsg = "This is an invalid entry\n\nThe previous date entry cannot be empty.\n\nPlease use the entry above first.";

app.beep();

app.alert(cMsg, nIcon, nType, cTitle);

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

102

Likes

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

CONFIRM SEQUENTIAL DATE ENTRIES

Community Beginner ,
Feb 25, 2019

Copy link to clipboard

Copied

I am attaching an image of a portion of a log page. As you see, there are multiple (six) identical records - each has a date field.

I need to do two things: 1) Assure that the date being entered does not predate the date field in the previous record, and 2)

verify that there is indeed a date in the date field of the previous record (avoid skipping records). Here is some code I have tried, but I cannot get the if condition to work:

Please share your thoughts.

//THIS VALIDATES THE DATE ENTERED

var cMsg = "The date you entered is invalid.\n\nPlease enter a date that does not pre-date the previous entry date.";

var nIcon = 0;

var nType = 0;

var cTitle = "DATE ERROR";

var str = event.target.name;

var res = str.charAt(str.length-1);

var d1 = Date.parse(this.getField("0." + (res-1)).value);

var d2 = Date.parse(event.value);

if (d1 == 0) {

if (d1 > d2) {

app.beep();

app.alert(cMsg, nIcon, nType, cTitle);

event.value = "";

}

} else {

var cMsg = "This is an invalid entry\n\nThe previous date entry cannot be empty.\n\nPlease use the entry above first.";

app.beep();

app.alert(cMsg, nIcon, nType, cTitle);

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

103

Likes

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
Feb 25, 2019 0
Most Valuable Participant ,
Feb 25, 2019

Copy link to clipboard

Copied

Date.parse("") does not return 0. It returns NaN.
I suggest you check if the value of the field equals an empty string directly, instead of this roundabout way.

Likes

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
Reply
Loading...
Feb 25, 2019 0
try67 LATEST
Most Valuable Participant ,
Feb 25, 2019

Copy link to clipboard

Copied

Another thing you're missing is the check whether the field number ("res") equals 1, because if it is then you shouldn't try looking for the previous field, as there isn't one.

Likes

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
Reply
Loading...
Feb 25, 2019 0