Skip to main content
Participating Frequently
June 27, 2024
Answered

EASY SOLUTION FOR SOMEONE, JUST NOT ME

  • June 27, 2024
  • 2 replies
  • 1815 views

I HAVE 2 FIELDS. A "TEST DATE" FIELD, WHICH I HAVE SETUP TO AUTOMATICALLY FILL IN TODAY'S DATE. FORMATED WITH DATE.

 

I HAVE ANOTHER FIELD "REG DATE" WHICH IS FORMATED THE SAME AS DATE. HOWEVER, THIS FIELD IS MANUALLY SELECTED BY THE USER.

 

WHAT I'D LIKE TO DO IS MAKE THIS "REG DATE" FIELD DISPLAY GREEN AND RED BASED ON THE DATE ENTERED. GREEN IF IT IS NOT PAST THE "TEST DATE" FIELD, BUT RED IF IT IS PAST "TEST DATE" FIELD. 

 

ANY IDEA'S HOW TO ACCOMPLISH THIS?

This topic has been closed for replies.
Correct answer try67

THANK YOU SO MUCH THIS DOES WORK. I BELEIVE IT PROBABLY WORKED THE LAST TIME TOO BUT I HAD MY FORM SET TO HIGHLIGHT ALL REQUIRED FIELDS AND THAT'S WHY IT WASN'T SHOWING UP AFTER YOU SELECTED THE DATES.

 

THE ONLY ISSUE I SEEN ON IT WAS THE ISSUE OF IF BOTH FIELDS HAVE THE SAME DATE IN THEM, THEN REG DATE IS RED. THAT SHOULD BE GREEN OR TRANSPARENT SO TO SPEAK. I'D LIKE TO GO AHEAD AND REMOVE THE GREEN AND JUST USE TRANSPARENT FOR GOOD TO GO AND RED FOR EXPIRED REGISTRATIONS. I TRIED TO TOY WITH THAT A LITTLE AND GOT A FEW ERRORS ON SYNTAX AND SUCH. 


Change the code to this:

 

if (event.value) {
	var testDate = util.scand("mm/dd/yyyy", this.getField("TESTDATE").valueAsString);
	testDate.setHours(0);
	testDate.setMinutes(0);
	testDate.setSeconds(0);
	testDate.setMilliseconds(0);
	var regDate = util.scand("m/d/yy", event.value);
	regDate.setHours(0);
	regDate.setMinutes(0);
	regDate.setSeconds(0);
	regDate.setMilliseconds(0);
	event.target.fillColor = (regDate.getTime()<testDate.getTime()) ? color.red : color.transparent;
} else event.target.fillColor = color.transparent;

2 replies

try67
Community Expert
June 28, 2024

- What is the date pattern used in these fields?

- What should be the color if the two dates are the same?

- What should happen if "TEST DATE" is empty and "REG DATE" is not?

Participating Frequently
June 28, 2024

THE DATE PATTERNS ARE:

- What is the date pattern used in these fields? "TEST DATE:"  FIELD IS: MM/DD/YYYY | "REG EXPIRE DATE:" FIELD IS: MM/DD/YY

- What should be the color if the two dates are the same? "TEST DATE:" FIELD SHOULDN'T CHANGE ANY COLORS

I WANT TO GET THE "REG EXPIRE DATE:" FIELD TO CHECK AGAINST THE TEST DATE FIELD. IF IT IS AN EARILER DATE THAN THE CURRENT DATE, I WANT IT TO FLAG THE FIELD RED. I DON'T NEED IT TO DO ANY GREEN AFTER I WAS THINKING ABOUT IT BUT, IF I DID, I'D LIKE IT TO BE GREEN IF IT'S GOOD, RED IF IT'S EXPIRED BASICALLY.

- What should happen if "TEST DATE" is empty and "REG DATE" is not? NEITHER OF THESE FIELDS CAN BE EMPTY. THEY ARE REQUIRED TO BE FILLED IN OR THE DOCUMENT WON'T ALLOW PRINTING. I HAVE THAT FIELD SCRIPTED TO AUTO ENTER THE CURRENT DATE WHEN THE PDF IS OPENED. 

 

 

Participating Frequently
July 11, 2024

I didn't get a notification about your reply from earlier due to a bug in the forums system...

You can use this code as the custom calculation script of the "REG DATE" field:

 

if (event.value) {
	var testDate = util.scand("mm/dd/yyyy", this.getField("TEST DATE").valueAsString);
	var regDate = util.scand("mm/dd/yyyy", event.value);
	event.target.fillColor = (regDate.getTime()<testDate.getTime()) ? color.red : color.green;
} else event.target.fillColor = color.transparent;

I tried this and it did not function. Does it make a difference if the fields are assigned a format category of Date with the dropdown calendar? i tried this in both custom validation script and custom caluclation script but netiher worked. 

 

i have another field there that does kind of simular which is the TOTALGVWR field. the code for this is located in the validate custom validation script: 

event.target.textColor = color.black;
if (+event.value > 26000) event.target.fillColor = color.green;
else if (+event.value < 26001) event.target.fillColor = color.red;

with 

TRLGVWR+PWRGVWR in the calculate tab simplified field notation. this works flawlessly but i can't figure out how to do this for 2 date boxes. 

 

The "SKILLS TEST DATE" field is set to automatcially fill in today's date with this code in the actions tab, mouse up, (run a javascript):

this.addScript("init", "this.getField(\"SKILLS TEST DATE\").value = new Date();");

 

i see the concept in your code and that's exactly what i'm looking for, minus the green portion. i'm looking for this to do the color change based on a mouse up or after a date is selected in the calendar picker.

If date of "REG DATE" is equal to OR after "SKILLS TEST DATE" then leave transparent.

if date of "REG DATE" is prior to "SKILLS TEST DATE" then change the color of the field to red. 

I'm not sure if this helps you any or not but i uploaded the file so you can see how this form works if that would be easier.

 

 

 

Amal.
Community Manager
Community Manager
June 27, 2024

Hi there

Hope you are doing well and thanks for reaching out.

The workflow you are trying to achieve is might be possible using JavaScript. For more information, please check the help pages listed below:
https://acrobatusers.com/tutorials/javascript_console/
https://helpx.adobe.com/acrobat/using/applying-actions-scripts-pdfs.html

Hope it will help

Regards
Amal