Adding additional values to placeholder text?

Community Beginner ,
Mar 06, 2019 Mar 06, 2019

Copy link to clipboard

Copied

I am trying to customize the text in the "placeholder" script for my fields. The script works great but would like to change the text color and size if possible. I have little to no experience with JavaScript. Can someone help me out? Thank you!

// Custom Format script for text field

if (!event.value) {

event.value = "Instructional text goes here";

event.target.display = display.noPrint;

} else {

event.target.display = display.visible;

}

TOPICS
Macintosh, PDF forms

Views

601

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
community guidelines
Most Valuable Participant ,
Mar 06, 2019 Mar 06, 2019

Copy link to clipboard

Copied

To set the font size:

event.target.textSize = 10;

To set the font color:

event.target.textColor = color.red;

The latter doesn't work with every color name, just some pre-defined ones. If you want a specific color you will need to use a more complex notation. For example, this will result in yellow text:

event.target.textColor = ["RGB", 1, 1, 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
community guidelines
Community Beginner ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

Thank you this worked great but I have two issues.

1)  I've made the "placeholder text" light grey but when the person fills out the form the type remains grey. I've tried to change the font color in the appearance tab but it won't let me. I'm assuming the script overrides the overall font color. Is there a way to make the font color black once they start filling in the field?

2) When using the specific text color "event.target.textColor = ["RGB", 1, 1, 0];", This doesn't seem like your normal RGB/HEX set of values. Is there a list or resource that shows how to match up a specific color? Example for an "orange" it would be RGB=(245, 115, 45)  /  HEX=f5732d. Any guidance would be appreciated.

Below is the script I currently have with your suggestions:

// Custom Format script for text field

if (!event.value) {

event.value = "Instructional text goes here";

event.target.textColor = color.ltGray;

event.target.textSize = 10;

event.target.display = display.noPrint;

} else {

event.target.display = display.visible;

}

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
community guidelines
Most Valuable Participant ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

1. You have to add a command to change it back to black in the "else" section. Personally, I prefer to do it using the On Focus and On Blur fields, so it executes the moment you enter or leave the field.

2. The values in Acrobat are between 0 and 1, so just divide your "normal" RGB values by 255 to get the correct result.

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
community guidelines
Community Beginner ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

Sorry if these seem like basis questions.

I added the text color and size to the "else" section but doesn't' seem to work. Is it a different command? See below.

if (!event.value) {

event.value = "First name";

event.target.textColor = color.ltGray;

event.target.textSize = 10;

event.target.display = display.noPrint;

}

else {

event.target.display = display.visible;

event.target.textColor = color.black;

event.target.textSize = 10;

}

Also, what would the same thing look like as "onfocus" and "onblur"?  Not sure if you put them together or just as it's a standalone script for the same thing? Here's what I got for this but not working as standalone or together. I'm sure you're laughing at this point. LOL!

// On Focus script:

if (event.target.value==event.target.defaultValue) {

    event.target.value = "";

    event.target.textColor = color.black;

}

// On Blur script:

if (event.target.value=="First name") {

    event.target.value = event.target.defaultValue;

    event.target.textColor = color.ltGray;

}

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
community guidelines
Most Valuable Participant ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

Yes, they need to be separate... The first part should be used as the field's On Focus script and the second as the On Blur script.

You'll find both under the Actions tab of the Properties dialog.

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
community guidelines
Community Beginner ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

I went to actions and created both onfocus and onblur then inserted the code for both "separately" but "placeholder text" doesn't show up. If I insert the original script (within format) that worked. The placeholder text shows up like before but when I input text into that field the color of the text remains light grey like the placeholder text. Where am I going wrong?

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
community guidelines
Most Valuable Participant ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

You need to put the placeholder text as the field's default value.

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
community guidelines
Community Beginner ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

I did put placeholder text but it is not showing up. Below is exactly what I have in both onfocus (text color when someone starts filling in the field), and onblur (text that appears in the field when its empty.

// On Focus script:

if (event.target.value==event.target.defaultValue) {

    event.target.value = "";

    event.target.textColor = color.black;

}

// On Blur script:

if (event.target.value=="First name") {

    event.target.value = event.target.defaultValue;

    event.target.textColor = color.ltGray;

}

Note: I have no scripts in 'format' customs, which is where the previous script was located.

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
community guidelines
Most Valuable Participant ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

Can you share the file with us (via Dropbox, Google Drive, Adobe Cloud, etc.)?

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
community guidelines
Most Valuable Participant ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

If you prefer to share it privately you can email it to me to try6767 at gmail.com and I'll take a look at it...

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
community guidelines
Community Beginner ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

I just emailed you the file. 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
community guidelines
New Here ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

I am having a similar issue with text staying gray when I start typing. It works (i.e. the text changes from grey to black) on single-line forms, but when I select "Multiline" under Options, this property goes away. I'm using the On Focus/On Blur scripts. Anyone know how I could have placeholder text that goes from grey to black in a multiline form? Thanks!

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
community guidelines
Most Valuable Participant ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

LATEST

Just tried my code in a multiline field and it worked fine. Share the file you're having issues with, please.

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
community guidelines