javascript color border
Copy link to clipboard
Copied
hello I am looking for an example of a javascript script for a form on acrobat as soon as the form field contains data I would like the border to be a blue color and as soon as the form field has no data I would like it to be red in color
Copy link to clipboard
Copied
Use a custom Validation or Custom Format Script
if(event.value && event.value.toString().length)
event.target.strokeColor = color.blue;
else
event.target.strokeColor = color.red;
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
first of all thank you for your return but the problem is that the event does not work to fill out a form I have to go through this.getField I have already tested
Copy link to clipboard
Copied
The script I posted is correct and works.
Did you try it out? In what event did you enter it?
Were any errors reported in the Console Window (Ctrl-J)?
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
I inject the data into the form via a crm
if I pass by putting your code directly in Adobe the event is taken into account and the color changes
but as soon as I inject them via the crm they are not taken into account I must in the javascript of the form variable I must put my javascript in the global document here is an example that I have tested but which only works halfway
{if (this.getField("works.remarks.1.remarks").value != "")
{
this.getField("works.remarks.1.remarks").borderWidth = 1;
}
else
{
this.getField("works.remarks.1.remarks").borderWidth = 0;
this.getField("works.remarks.1.remarks").borderColor = color.black;
}
}
Copy link to clipboard
Copied
All JavaScript is event driven. So if you are "injecting it via a CRM", then it is being run in an event. I suspect it is running immediately against the document object. This won't work for you. Why can't you modify the form up front with the correct code before it is added to the CRM system?
Also, this method, "injection via CRM" is critical information. You did us all a disservice by not explaining this in your first post. In fact you ignored it for several posts. If you want help, you have to provide all relevant information.
If this is not possible, the use the "field.setAction()" function in your CRM injection to put the script where it needs to be.
Here's an example using the pattern provided by ls_rbs above:
var strValScript = "event.target.strokeColor = (event.value && event.value.toString().length)?color.blue:color.red;";
this.getField("works.remarks.1.remarks").setAction("Validate",strValScript);
If the form is then saved, then the validation script will be saved with it.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
I just took the test again
it works when i open it with adobe but when i inject the data with the crm it doesn't work
Copy link to clipboard
Copied
Are you sure Acrobat is the viewer used by the CRM app?
Are there any errors reported by the CRM app when the code is injected?
Did you check the PDF after injection to see if the Validate script was actually inserted?
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Hi ,
This can be accomplished with various scripting methods.
In my example below, I decided to use a custom fomat keystroke script.
(event.willCommit && (event.value =="")) ? event.target.strokeColor = color.red : event.target.strokeColor = color.blue;

