Link in Zwischenablage kopieren
Kopiert
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();");
}
Link in Zwischenablage kopieren
Kopiert
In field properties, you can set it to be visible but doesn't print.
Link in Zwischenablage kopieren
Kopiert
wouldn't that not print text as well if someone has already filled out the form? not really what i'm after
Link in Zwischenablage kopieren
Kopiert
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).
Link in Zwischenablage kopieren
Kopiert
Link in Zwischenablage kopieren
Kopiert
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?
Link in Zwischenablage kopieren
Kopiert
No, you have to apply a call to the function under both triggers, but this can also be automated using a script.
Link in Zwischenablage kopieren
Kopiert
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?
Link in Zwischenablage kopieren
Kopiert
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();");
}
Link in Zwischenablage kopieren
Kopiert
Thank you so much for your time/help, that is way better!
Link in Zwischenablage kopieren
Kopiert
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?
Link in Zwischenablage kopieren
Kopiert
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?
Link in Zwischenablage kopieren
Kopiert
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();");
}
Link in Zwischenablage kopieren
Kopiert
thank you so so much for your help, this will save so much time!!
Weitere Inspirationen, Events und Ressourcen finden Sie in der neuen Adobe Community
Jetzt ansehen