10 Replies Latest reply on Jan 31, 2018 9:29 AM by Thom Parker

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

    cschmelter Level 1

      Is this possible or no?

        • 1. Re: Programmatically change name/label of "static_text" field in dialog
          Joel_Geraci Adobe Community Professional

          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.

          • 2. Re: Programmatically change name/label of "static_text" field in dialog
            Thom Parker Adobe Community Professional

            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

            1 person found this helpful
            • 3. Re: Programmatically change name/label of "static_text" field in dialog
              try67 MVP & Adobe Community Professional

              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...

              • 4. Re: Programmatically change name/label of "static_text" field in dialog
                cschmelter Level 1

                Awesome. That worked for me:

                 

                dialog.load({ "myid": "Some New Caption" });
                
                • 5. Re: Programmatically change name/label of "static_text" field in dialog
                  try67 MVP & Adobe Community Professional

                  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)
                  
                  • 6. Re: Programmatically change name/label of "static_text" field in dialog
                    cschmelter Level 1

                    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.

                    • 7. Re: Programmatically change name/label of "static_text" field in dialog
                      cschmelter Level 1

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

                      • 8. Re: Programmatically change name/label of "static_text" field in dialog
                        try67 MVP & Adobe Community Professional

                        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!

                        • 9. Re: Programmatically change name/label of "static_text" field in dialog
                          cschmelter Level 1

                          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.

                          • 10. Re: Programmatically change name/label of "static_text" field in dialog
                            Thom Parker Adobe Community Professional

                            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.