• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Form fill colour on focus/blur

New Here ,
Sep 19, 2023 Sep 19, 2023

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;
}
}
}
}

TOPICS
Acrobat SDK and JavaScript

Views

303

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Sep 22, 2023 Sep 22, 2023

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();");
}

Votes

Translate

Translate
Community Expert , Sep 26, 2023 Sep 26, 2023

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();");
}

Votes

Translate

Translate
Community Expert ,
Sep 19, 2023 Sep 19, 2023

Copy link to clipboard

Copied

In field properties, you can set it to be visible but doesn't print.

 

tempsnip.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 20, 2023 Sep 20, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2023 Sep 20, 2023

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).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2023 Sep 20, 2023

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 20, 2023 Sep 20, 2023

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 21, 2023 Sep 21, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 21, 2023 Sep 21, 2023

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? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2023 Sep 22, 2023

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();");
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 24, 2023 Sep 24, 2023

Copy link to clipboard

Copied

Thank you so much for your time/help, that is way better! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 25, 2023 Sep 25, 2023

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 25, 2023 Sep 25, 2023

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2023 Sep 26, 2023

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();");
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 02, 2023 Oct 02, 2023

Copy link to clipboard

Copied

LATEST

thank you so so much for your help, this will save so much time!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines