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

How to change the font of a specific variable?

Explorer ,
May 24, 2017 May 24, 2017

Rich text formatting is selected.

this is a javascript question.

This is a calculated field for a form field.

I just want 1 variable, no array needed. I would like my variable to be bold, centered, and larger font.

What I currently have... which do nothing...

var val = getField("Products").value;

val.alignment = "center";

val.fontStyle = font.TimesB

TOPICS
Acrobat SDK and JavaScript , Windows
3.9K
Translate
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

Explorer , May 25, 2017 May 25, 2017

No thank you. I'll try a different forum.

Translate
Community Expert ,
May 24, 2017 May 24, 2017

You must use span objects. Read the documentation in the Acrobat JavaScript Reference.

Translate
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
Explorer ,
May 24, 2017 May 24, 2017

WIth all due respect, I have read it, that's why I'm here. Its vague instructions aren't solving my problem.

I want the variable val to be bold, center, and larger. Part of the code is:

var val = getField("Products").value;

if (typeof val === "object") {

        for (i = 0; i < val.length; i += 1) {

            aLines.push(val + ":\n\t " + oDescriptions[val]);

        }

    } else {

        aLines.push(val + ":\n\t " + oDescriptions[val]);

  }

     // Set this field value

    event.value = aLines.join("\r");

})();

Translate
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 ,
May 24, 2017 May 24, 2017

Why didn't you change the properties of the field?

Translate
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
LEGEND ,
May 24, 2017 May 24, 2017

Your code seems to have no connection to setting a span object. Which, the documentation states, is an array. Not sure why you say no array is needed, what do you know that the authors don't?

Translate
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
Explorer ,
May 24, 2017 May 24, 2017

That they haven't given me a specific answer. Professional programmers agent on forums for answered. I'll think of a third

Translate
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
LEGEND ,
May 24, 2017 May 24, 2017

The trouble with saying that documentation is vague is that it's very difficult to help you. Documentation is often vague, it's true, but it's often all we have. All we could do for reply is quote from the documentation. But for complex topics that means quoting a lot of material and you've already said it's too vague to help you. I suggest if still stuck you say exactly what the documentation seems to miss out or what exact words are ambiguous. That helps us to answer your specific questions and fill in gaps in your knowledge. And it shows us you are actually looking at the document, rather than expecting someone else to write the code, because we have sometimes found accusations of vagueness actually just mean the work hadn't been done.

Translate
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
Explorer ,
May 25, 2017 May 25, 2017

In http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf , there's spans[0] through spans [3]; I don't want to have to type each text out that could result. I want a one size fits all for all variables, especially as I add more

Translate
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 ,
May 24, 2017 May 24, 2017

You don't actually need Rich Text to be checked if you aren't going to have multiple styles in the field. The problem you are having is that you are trying to set field properties on the field value rather than the field object itself. You were also using the wrong property name for the font.

See corrected code below.

var val = this.getField("Products");

val.alignment = "center";

val.textFont = font.TimesB

Translate
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
Explorer ,
May 24, 2017 May 24, 2017

Thanks for the correction... nothing happened. The entire field is still left aligned and not bold

Translate
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 ,
May 24, 2017 May 24, 2017

Where exactly are you putting the code?

Translate
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
Explorer ,
May 25, 2017 May 25, 2017

(function () {

     // Initialize some variables

    var i, aLines = [];

    // Associate states with a description

    var oDescriptions = {

"Term" : "\nIssue ",

"Term - " : "This is a term with return of premium available",

"Term - " : "\nIssue Ages:",

"Whole Life -" : "This is a whole life"

    }

    // Get the selections from the list box

var val = this.getField("Products").value;

val.alignment = "center";

val.textFont = font.TimesB;

    if (typeof val === "object") {

        for (i = 0; i < val.length; i += 1) {

            aLines.push(val + ":\n\t " + oDescriptions[val] + "\n===================================================================================="); //This is the line break I am using that I am trying to replace

        }

    } else {

        aLines.push(val + ":\n\t " + oDescriptions[val]);

  }

    // Set this field value

    event.value = aLines.join("\r");

})();

Translate
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 ,
May 25, 2017 May 25, 2017

This is wrong:

nathanm54209085  wrote

...

var val = this.getField("Products").value;

val.alignment = "center";

val.textFont = font.TimesB;

...

You can change the properties of the field.

Translate
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
Explorer ,
May 25, 2017 May 25, 2017

I haven't changed the properties of the field... BECAUSE AS I HAVE STATED,  ONLY THE VAL HEADERS NEED TO BE DIFFERENT

Translate
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 ,
May 25, 2017 May 25, 2017

nathanm54209085  wrote

I haven't changed the properties of the field... BECAUSE AS I HAVE STATED,  ONLY THE VAL HEADERS NEED TO BE DIFFERENT

I don't see this information in your posting.

Again: When you want different text styles in one text field you must use span objects and rich text formatting.

Translate
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
Explorer ,
May 25, 2017 May 25, 2017

Again: not to be rude, I'm here for a solution. Not a homework assignment

Translate
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 ,
May 25, 2017 May 25, 2017

I give up. Good luck!

Translate
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 ,
May 24, 2017 May 24, 2017

What happens when you change the property of the field?

Translate
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
LEGEND ,
May 25, 2017 May 25, 2017

A hint: you need to work with the field properties, not the value properties. So you have a  .value  that is quite wrong.

Translate
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
Explorer ,
May 25, 2017 May 25, 2017

Can I please get the answer... I don't care about hints,  vague ideas,  homework assignments,  suggestions to Google, or repeating what I've already said.

I just want it to work

Translate
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
LEGEND ,
May 25, 2017 May 25, 2017

Ok. The last bit of code had  ".value" on the first line. Take it off, it does not belong.

Commentary: You have made an error by putting it there and refusing to remove it despite repeated attempts to send you in the right direction. Look at the description of the Field class, and its properties. Don't assume that "value" means any more than exactly what it says, don't try to use what you know about English to extrapolate.

Translate
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
Explorer ,
May 25, 2017 May 25, 2017

I've tried it without or with it. Still no font or alignment change.

Commentary: if you highlight my text,  press Ctrl + c, then Ctrl +v into the reply field.  You can make the exact changes I've been requesting, then click post. I will get my solution that I've been begging for, and you'll get a well deserved thank you. And then this forum will be vindicated as a forum, not a tutoring session.

Translate
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
LEGEND ,
May 25, 2017 May 25, 2017

Please post the specific code you are now trying to use. Without the .value where I said. It's generally impossible to know what code someone is now using by the time you factor in inexperience, typos and wild frustration. Yes, wild frustration, I've been programming for decades and that is a continuing normal experience that never goes away.

Translate
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
Explorer ,
May 25, 2017 May 25, 2017

(function () {

    // Initialize some variables

    var i, aLines = [];

    // Associate states with a description

    var oDescriptions = {

"Term" : "\nIssue Ages:\t\t10 Y",

"Term - Am" : "This",

"Term - " : "\nIssue Ag",

"Whole Life - Amer" : "This is a whole life"

    }

    // Get the selections from the list box

    var val = getField("Products").;

    if (typeof val === "object") {

        for (i = 0; i < val.length; i += 1) {

            aLines.push(val + ":\n\t " + oDescriptions[val] + "\n====================================================================================");

        }

    } else {

        aLines.push(val + ":\n\t " + oDescriptions[val]);

  }

    // Set this field value

    event.value = aLines.join("\r");

})();

Translate
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 ,
May 25, 2017 May 25, 2017

I'll need to see the actual form before supplying any more help.

Translate
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