Copy link to clipboard
Copied
Good morning ladies and gentlemen!
I recently created an inspection report which contains various 'Year service is due' fields. When I enter a past or present year, I'd like the cell background to turn red. If I enter a future year, I'd like the cell background to stay white. I don't know how to write code but I assume I can create a java script in this case. Can someone please assist?
Thank you in advance!
Copy link to clipboard
Copied
Are you entering a full date (eg. "22/06/2018"), or just the year (eg. "2018")?
Copy link to clipboard
Copied
Also, what should happen if the field is empty?
Copy link to clipboard
Copied
Remains white.
[Moderator Note: Personal information removed. Please turn off email signatures when replying to forum posts.]
Copy link to clipboard
Copied
You can use this code as the field's custom validation script:
if (event.value!="" && new Date().getFullYear()>=Number(event.value)) {
event.target.fillColor = color.red;
} else event.target.fillColor = color.white;
Copy link to clipboard
Copied
Thank you very much. I'm sure you're right but with my limited code experience, I think I may be inputting it incorrectly. I just copy and past your script in the 'Create and Edit JavaScript' window correct? I did this and nothing changes. Do you know what I may be doing wrong? Do I need to delete any spaces? Does the file always know the current year when I open it on my ipad or computer? Thank you again!
Copy link to clipboard
Copied
Where exactly did you place the code?
It will work on a computer (if you use Adobe software). It might not work on a mobile device.
Copy link to clipboard
Copied
I’m using a windows desktop to create the fill-able pdf in Adobe Pro DC. Then I copy said pdf to my Dropbox and upload it in Adobe Pro on my iPad. I fill out the report while in the field via said iPad.
I opened the pdf on my desktop, clicked Tools > Prepare. Then clicked on a cell in the top row, Properties > Validate > Check the ‘Custom Java Script’ radio button > Edit > Paste (pasted your script). Then, I hit Close > Preview > entered 2017, and the bg stayed white. When I click on the cell to change it again, it flashes red but returns to white.
[Moderator Note: Personal information removed. Please turn off email signatures when replying to forum posts.]
Copy link to clipboard
Copied
Also, when I input a year less than 2019, the cell will remain light blue (fillable color). When I edit the year, it stays red background until the year is 2019 or after, but regardless of the year, the background remains light blue when not being edited.
Copy link to clipboard
Copied
You need to disable the fields highlighting option.
Copy link to clipboard
Copied
try67...thank you so much - that was the problem! Thank you for the quick response and patience. Have a great day!
Copy link to clipboard
Copied
Just the year.
[Moderator Note: Personal information removed. Please turn off email signatures when replying to forum posts.]