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

Community Beginner ,
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

}

}

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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;
}
TOPICS
Acrobat SDK and JavaScript

Views

56

Likes

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

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

Community Beginner ,
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

}

}

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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;
}
TOPICS
Acrobat SDK and JavaScript

Views

57

Likes

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
Nov 24, 2020 0
Most Valuable Participant ,
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;
}

Likes

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
Reply
Loading...
Nov 24, 2020 0
Community Beginner ,
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

Likes

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
Reply
Loading...
Nov 24, 2020 0
Adobe Community Professional ,
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. 

Likes

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
Reply
Loading...
Nov 24, 2020 0
Adobe Community Professional ,
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];

 }
 

}

 

Likes

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
Reply
Loading...
Nov 24, 2020 0
Community Beginner ,
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;

}

}

Likes

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
Reply
Loading...
Nov 24, 2020 0
Adobe Community Professional ,
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;

 

Likes

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
Reply
Loading...
Nov 24, 2020 0
New Here ,
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.

Likes

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
Reply
Loading...
Dec 07, 2020 0
ls_rbls LATEST
Adobe Community Professional ,
Dec 11, 2020

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
Dec 11, 2020 0
Engaged ,
Nov 24, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Nov 24, 2020 1
Adobe Community Professional ,
Nov 24, 2020

Copy link to clipboard

Copied

Good idea!

Likes

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
Reply
Loading...
Nov 24, 2020 1
Community Beginner ,
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. 

Likes

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
Reply
Loading...
Nov 24, 2020 0
Community Beginner ,
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. 

Likes

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
Reply
Loading...
Nov 24, 2020 0
Adobe Community Professional ,
Nov 24, 2020

Copy link to clipboard

Copied

You can select multiple fields and change the properties.

Likes

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
Reply
Loading...
Nov 24, 2020 1