Skip to main content
Participant
November 24, 2020
Answered

Javacript for Auto font/Size/Color/options for text Fields and Checkboxes

  • November 24, 2020
  • 4 replies
  • 2859 views

I created a script for my text fields to default to the following settings:

Font Size: 10

Font Color: Blue

Font: Times-Roman

This is working for the most part. However, I would also like to add another default setting for text field, under the option tab only have the "check spelling" box selected.

 

Also, the current script is not being applied to checkboxes. I would like checkboxes to have the same default setting (Blue, 10) with the check box style set to "cross".

 

Below is my current script, can I please get assistance with the above additional settings added to my existing script?

 

/* Auto Detect Font Changer */
for (var i = 0; i < numFields; i++) {

var fName = getNthFieldName(i);

var f = getField(fName);

if (f.type === "text") {

f.alignment ="left";

f.textFont = "Times-Roman";

f.textSize = 10;

f.textColor = ["CMYK",1,1,0,0];

// Other properties go here

}

}

This topic has been closed for replies.
Correct answer try67

You can use this code:

 

if (f.type === "text") {
	f.alignment ="left";
	f.textFont = "Times-Roman";
	f.textSize = 10;
	f.textColor = ["CMYK",1,1,0,0];
	f.doNotSpellCheck = false;
} else if (f.type=="checkbox") {
	f.textSize = 10;
	f.textColor = ["CMYK",1,1,0,0];
	f.style = style.cr;
}

4 replies

Bernd Alheit
Community Expert
Community Expert
November 24, 2020

You can select multiple fields and change the properties.

Inspiring
November 24, 2020

Why just not use "Use Current Properties as New Defaults"?

ls_rbls
Community Expert
Community Expert
November 24, 2020

Good idea!

Participant
November 24, 2020

If this is as close as I can get, I am very happy! I sure beats changing all the settings everytime I had to "prepare a form". Thanks for your help. 

ls_rbls
Community Expert
Community Expert
November 24, 2020

It should work with this:

 

/* Auto Detect Font Changer */
for (var i = 0; i < numFields; i++) {

var fName = getNthFieldName(i);

var f = getField(fName);

if (f.type === "text") {

f.alignment ="left";

f.textFont = "Times-Roman";

f.textSize = 10;

f.textColor = ["CMYK",1,1,0,0];

// Other properties go here

//enable the spellcheck but also  let the user to manually select a dictionary

(f.spell.available).value = spell.checkText(f.value);

   }
 
if (f.type === "checkbox") {
f.style ="cross";
f.textColor = ["CMYK",1,1,0,0];

 }
 

}

 

Participant
November 24, 2020

Hi,

 

The "check spelling" is checked, but it is still auto checking the "multi line" and "scroll long text". 

 

Here is the script:

/* New- Auto Detect Font Changer */
for (var i = 0; i < numFields; i++) {

var fName = getNthFieldName(i);

var f = getField(fName);

if (f.type === "text") {

f.alignment ="left";

f.textFont = "Times-Roman";

f.textSize = 10;

f.textColor = ["CMYK",1,1,0,0];

f.doNotSpellCheck = false;
} else if (f.type=="checkbox") {
f.textSize = 10;
f.textColor = ["CMYK",1,1,0,0];
f.style = style.cr;

}

}

ls_rbls
Community Expert
Community Expert
November 24, 2020

ultiline and scroll long text is not autocheked by the script.

 

That is a last remeber state on how the fields are created by default with those properties enabled.

 

Following Asim suggestion you can create one field with those property appearance preferences disabled  and then right-click  and select from the context menu "Use Current Properties as New Defaults". Then create your children fields based on this parent field.

 

But this can also be  manipulated via script.

 

you can add a line to your actual script like :

 


f.multiline = false;
f.doNotScroll = true;

 

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 24, 2020

You can use this code:

 

if (f.type === "text") {
	f.alignment ="left";
	f.textFont = "Times-Roman";
	f.textSize = 10;
	f.textColor = ["CMYK",1,1,0,0];
	f.doNotSpellCheck = false;
} else if (f.type=="checkbox") {
	f.textSize = 10;
	f.textColor = ["CMYK",1,1,0,0];
	f.style = style.cr;
}
Participant
November 24, 2020

Hi,

Thanks for your help. All seems to work as intended. Is it possible to have the check box only have the "check spelling" selected and no other box? Currently the script is still selecting three options rather than just the one I want.

ls_rbls
Community Expert
Community Expert
November 24, 2020

I don't thinkthe font size part of the script will be respected by the checkbox widget though. So that line doesn't seem to be necessary. The font for a checkbox or radio button is set by default as Adobe Pi and that appearance property cannot be changed or affect a cross, circle, square, or a checkmark for example.