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

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

Community Beginner ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

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

}

}

TOPICS
Acrobat SDK and JavaScript

Views

1.5K

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 1 Correct answer

Community Expert , Nov 24, 2020 Nov 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;
}

Votes

Translate

Translate
Community Expert ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

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

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 Beginner ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

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.

check box options.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
Community Expert ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

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. 

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 ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

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

 }
 

}

 

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 Beginner ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

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;

}

}

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 ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

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;

 

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 Beginner ,
Dec 07, 2020 Dec 07, 2020

Copy link to clipboard

Copied

Please tell me how to format text using a script. Negative numbers need to be red and 1 unit more than positive numbers.

 

Thank you.

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 ,
Dec 11, 2020 Dec 11, 2020

Copy link to clipboard

Copied

LATEST

Hi Andrew,

 

Sorry we missed your inquiry.

 

Can you be a little more specific about what you're trying achieve?

 

How to format text using a script has alaready being addressed in this topic. Maybe what you need is how to elaborate a condition, so that when a value is less than 0 the text color change to red in that field, for example. 

 

I didn't understand the part where you say "one unit more than positive numbers" though.

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
Enthusiast ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

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

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 ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

Good idea!

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 Beginner ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

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. 

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 Beginner ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

Hi,

 

I've tried this before, but it doesnt apply when you use "prepare form" with auto detection. It only works if you create a new text manually. 

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 ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

You can select multiple fields and change the properties.

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