Copy link to clipboard
Copied
Hi,
I'm a bit stuck with a form I have been given with some Javascript that has both on focus and on blur triggers. The downside to this is that each field needs to have two Javascript tigger set, which gets super time consuming on a large form.
What I would like is it to is fill the yellow on focus and then set back to trasparent in the same bit of code (saving me from having to add the on Blur trigger) or set when it printing the document to be transparent but i'm not sure if that is possible?.
below is the code that has been used in these old forms i'm updating.
function HiLite()
{
if (app.viewerVersion > 4.05)
{
var MyField = event.target;
var rgEmptyTest = /^\s*$/;
color.ltYellow = new Array("RGB",1,0.994,0.820);
if(event.name == "Focus")
{
if(MyField.type == "button")
{
MyField.borderColor = color.red;
}
else
{
MyField.fillColor = color.ltYellow;
}
}
else if(event.name == "Blur")
{
if(rgEmptyTest.test(event.value))
{
MyField.fillColor = color.transparent;
MyField.borderColor = color.transparent;
}
else
{
MyField.fillColor = color.transparent;
MyField.borderColor = color.transparent;
}
}
}
}
You can run this code from the JS Console to apply the script to both actions of all the fields in the file:
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
f.setAction("OnFocus", "HiLite();");
f.setAction("OnBlur", "HiLite();");
}
Try this:
var fieldsToExclude = ["SignField", "Save", "Clear", "Print"];
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
if (fieldsToExclude.indexOf(fname)!=-1) continue;
var f = this.getField(fname);
f.setAction("OnFocus", "HiLite();");
f.setAction("OnBlur", "HiLite();");
}
Copy link to clipboard
Copied
In field properties, you can set it to be visible but doesn't print.
Copy link to clipboard
Copied
wouldn't that not print text as well if someone has already filled out the form? not really what i'm after
Copy link to clipboard
Copied
You can change display state of a field with a script, for example as Document action 'Will Print' you can check if the fields are empty and change their state to 'doesn't print' (display.noPrint).
Copy link to clipboard
Copied
Copy link to clipboard
Copied
so there is no way to get this to function with just using 'on focus' trigger? the code in the link looks like a simpler version of the code thats being used but till needs both 'on focus' and 'on blur' triggers?
Copy link to clipboard
Copied
No, you have to apply a call to the function under both triggers, but this can also be automated using a script.
Copy link to clipboard
Copied
Hi Thanks for the claification, sorry if this sounds silly but can you please explain how i can get this to work like that? its been a while since i've had to do Javascript and its not my strongest suit. Do i use both a combination of the script i have been given above and the one you linked to?
Copy link to clipboard
Copied
You can run this code from the JS Console to apply the script to both actions of all the fields in the file:
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
f.setAction("OnFocus", "HiLite();");
f.setAction("OnBlur", "HiLite();");
}
Copy link to clipboard
Copied
Thank you so much for your time/help, that is way better!
Copy link to clipboard
Copied
Sorry, i do have one more question, if you can help please? is there a way to exclude a field from that code? for example i have a signature ("SignField") that i have a slightly different version of the HiLite applyed to it but that code above overwites that, can i fix that by excluding it somehow?
Copy link to clipboard
Copied
oh also relised I need to apply an exclusion to a few other fields that have set colour as well that i don't want changed it it possible just to exclude those 4 field names ("SignField", "Save", "Clear" And "Print") from the loop?
Copy link to clipboard
Copied
Try this:
var fieldsToExclude = ["SignField", "Save", "Clear", "Print"];
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
if (fieldsToExclude.indexOf(fname)!=-1) continue;
var f = this.getField(fname);
f.setAction("OnFocus", "HiLite();");
f.setAction("OnBlur", "HiLite();");
}
Copy link to clipboard
Copied
thank you so so much for your help, this will save so much time!!