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

Programmatically change name/label of "static_text" field in dialog

Explorer ,
Jan 30, 2018 Jan 30, 2018

Copy link to clipboard

Copied

Is this possible or no?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

831

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 , Jan 30, 2018 Jan 30, 2018

I think he means in a dialog object

And yes you can, just use the dialog.load function. Same as it's used in the "initialize" function

Votes

Translate

Translate
Community Expert ,
Jan 30, 2018 Jan 30, 2018

Copy link to clipboard

Copied

You can't use Acrobat JavaScript to change the name of a field. However, you can collect up all the properties of a field, delete it, create a new field with the name you want and apply the properties of the old field to the new field.

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 ,
Jan 30, 2018 Jan 30, 2018

Copy link to clipboard

Copied

I think he means in a dialog object

And yes you can, just use the dialog.load function. Same as it's used in the "initialize" function

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jan 30, 2018 Jan 30, 2018

Copy link to clipboard

Copied

Are you sure about that? The name property of a static_text component can be changed in the initialize event?

I just tried it and it didn't work...

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
Explorer ,
Jan 31, 2018 Jan 31, 2018

Copy link to clipboard

Copied

Awesome. That worked for me:

dialog.load({ "myid": "Some New Caption" });

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 ,
Jan 31, 2018 Jan 31, 2018

Copy link to clipboard

Copied

Not working for me... Can someone point out what's wrong with this code?

var dialog1 = {

    initialize: function (dialog) {

        dialog.load ({"lbl1": "Caption:"});

    },

    cancel: function(dialog) {

        return;

    },

    destroy: function(dialog) {

        return;

    },

    commit:function (dialog) {

        return;

    },

    validate:function (dialog) {

        return true;

          

    },

    description: {

        name: "Test Dialog",

        align_children: "align_left",

        width: 350,

        height: 100,

        elements:[

            {

                type: "cluster",

                name: "",

                align_children: "align_left",

                elements:[

                {

                    type: "view",

                    align_children: "align_distribute",

                    elements:[

                        {

                            item_id: "lbl1",

                            type: "static_text",

                        },

                        {

                            item_id: "txt1",

                            type: "edit_text",

                            width: 200,

                            height: 25

                        }

                    ]

                },

                {

                    alignment: "align_right",

                    type: "ok_cancel",

                    ok_name: "OK",

                    cancel_name: "Cancel"

                },

              

                ]

            },

          

        ]

    }

};

app.execDialog(dialog1)

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
Explorer ,
Jan 31, 2018 Jan 31, 2018

Copy link to clipboard

Copied

It seems the size of the field doesn't dynamically change when you change the caption. So since you don't specify the "name" property in the element definition, it's probably sizing the field with a very small width which is probably why you can't see the caption. Try specifying a name up front. In my case, I'm lucky because the two captions I'm toggling between are very similar in character length.

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
Explorer ,
Jan 31, 2018 Jan 31, 2018

Copy link to clipboard

Copied

So just make sure you set the initial name to the longest possible value.

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 ,
Jan 31, 2018 Jan 31, 2018

Copy link to clipboard

Copied

Actually, that's not necessary, but your reply did bring me to the right solution. I was missing the width setting for the field, and since its original value is empty, it probably defaults to 0. So all you need to do is set it in the description and then it works. Neat!

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
Explorer ,
Jan 31, 2018 Jan 31, 2018

Copy link to clipboard

Copied

Ah right, you can either specify a name up front and it will automatically determine the width based on that or just specify the width like you did. I don't have width set on mine.

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 ,
Jan 31, 2018 Jan 31, 2018

Copy link to clipboard

Copied

LATEST

Correct!  Many of the fields have default sizes and many do not. This mostly this lack of sizing applies to the width. So something has to be in there to give it the initial size. An alternative is to set the alignment to "align_fill". This expands the field to the width of it's container. So of course the container has to have a size as well. I usually set it's alignment to "align_fill" as well, and so on up the tree.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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