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

help modify the script

Enthusiast ,
Jul 25, 2020 Jul 25, 2020

Copy link to clipboard

Copied

Could someone possibly help me and modify code for me?

I would need to change from  "edit_text" to "popup" with selections t1,t2,t3 and "ok" button to write selections to text field. I'm trying this whole day and just can't figure it out.

 

var dlg =  {
   commit: function(dialog)
   {
      var data = dialog.store();
      this.strName = data["usnm"];
   },
butn: function(dialog){
   dialog.end("butn");
},
    description:  { name: "", elements: [
  {
type: "static_text",
name: "",
char_width: 15,
alignment: "align_center",
font: "dialog",
bold: true,
},      
{ type: "cluster", name: "",elements: [
    	{ name: "", type: "static_text", },           	
    ] },
{ type: "cluster", align_children: "align_row", elements: [
{ name: "", type: "static_text", },
{ item_id: "usnm", type: "edit_text", char_width: 4, },
{
type: "button",
item_id: "butn",
name: "Reset"
}
]},
{ type: "ok_cancel",
        ok_name: "Ok",
        cancel_name: "Cancel",
        },
] }
 };

var dialogReturnValue = app.execDialog(dlg);
if ("ok" == dialogReturnValue) {
this.getField("field").value = dlg.strName;
} else if ("butn" == dialogReturnValue) {
this.getField("field").value = "";
}

 

 

TOPICS
Acrobat SDK and JavaScript

Views

545

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 , Jul 26, 2020 Jul 26, 2020

You've aleady learned that a list field on a dialog is populated with a object. Where the item names are the text that appears in list, and the item value is "1" for a selected item and "-1" for an unselected item. 

Now, getting a value from a list is exactly the same. 

 

dialog.store()["usnm"];

 

This code returns an object. To the get selected item, the code needs to examine each item in the object to find the one that has a value of "1".  

Here's the code you need in the "commit" function

 

v
...

Votes

Translate

Translate
Community Expert ,
Jul 25, 2020 Jul 25, 2020

Copy link to clipboard

Copied

What errors are you getting?

 

Open the console and see what messages are posted.

 

I am learning Acrobat javascript and your script seems a bit too advanced for my current level.

 

However, I can't help but notice a bunch of comas "," that in my humble opinion, appear to be unnecessary (or wrong) with some of the parameters that end with the closing curly brace "}".

 

For example see the following lines used in your script:

{ type: "cluster", name: "",elements: [
{ name: "", type: "static_text", },
] },
{ type: "cluster", align_children: "align_row", elements: [
{ name: "", type: "static_text", },

 

Can you confirm if this is how they should be expressed:

 

 

 

{ type: "cluster", name: "",elements: [
    	{ name: "", type: "static_text"},           	
    ] },
{ type: "cluster", align_children: "align_row", elements: [
{ name: "", type: "static_text"},

 

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
Enthusiast ,
Jul 25, 2020 Jul 25, 2020

Copy link to clipboard

Copied

Inside commas goes text which I deleted for this post,code is working fine I just want to change it from input field to popup selection.

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 ,
Jul 26, 2020 Jul 26, 2020

Copy link to clipboard

Copied

Change:

{ item_id: "usnm", type: "edit_text", char_width: 4, },

To:

{ item_id: "usnm", type: "popup", char_width: 4, },

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
Enthusiast ,
Jul 26, 2020 Jul 26, 2020

Copy link to clipboard

Copied

Hi try67,  I don't know how to add selection to that popup(example:text1,text2...etc) and also ok button to write my selection to textfield.

EDIT:

I managed to make some progress but when I press ok button in my textfield it says "undefined" can you take a look and let me know what I need to change to make "ok" write my choice to textfield.

var dlg =  {
  initialize: function(dialog) {
this.loadDefaults(dialog);
},
 commit: function(dialog)
   {
      var data = dialog.store()["usnm"];
      this.strName = data["usnm"];
   },
other: function(dialog){
   dialog.end("other");
},
loadDefaults: function (dialog) {
dialog.load({
usnm:
{
"1": 1,
"2": -1,
"3": -2
}
})
},
    description:  { name: "text", elements: [
      {
type: "static_text",
name: "CUSTOM TITLE",
char_width: 15,
alignment: "align_center",
font: "dialog",
bold: true,
},  
{ type: "cluster", name: "text",elements: [
    	{ name: "text",
 type: "static_text",
 char_height: 4 },           	
    ] },
{ type: "cluster", align_children: "align_row", elements: [
{ name: "text", type: "static_text", },
{ item_id: "usnm", type: "popup", char_width: 20, },
]},
{ type: "ok_cancel_other",
        ok_name: "Ok",
        cancel_name: "Cancel",
        other_name: "Reset" },
] }
 };

var dialogReturnValue = app.execDialog(dlg);
if ("ok" == dialogReturnValue) {
this.getField("field").value = dlg.strName;
} else if ("other" == dialogReturnValue) {
this.getField("field").value = "0";
}

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 ,
Jul 26, 2020 Jul 26, 2020

Copy link to clipboard

Copied

You've aleady learned that a list field on a dialog is populated with a object. Where the item names are the text that appears in list, and the item value is "1" for a selected item and "-1" for an unselected item. 

Now, getting a value from a list is exactly the same. 

 

dialog.store()["usnm"];

 

This code returns an object. To the get selected item, the code needs to examine each item in the object to find the one that has a value of "1".  

Here's the code you need in the "commit" function

 

var oList = dialog.store()["usnm"];
this.strName = "";
for(var nm in oList)
{
    if(Number(oList[nm]) > 0)
    {
       this.strName = nm;
       break;
    }
}

 

 On a separate note, there is no need to have a "loadDefaults" function. It just over complicates the code. 

 

You can find out more about programming Acrobat JavaScript dialogs, and also find a drag and drop tool that created the dialog code for you here:

https://www.pdfscripting.com/public/ACRODIALOGS-OVERVIEW.cfm

 

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
Enthusiast ,
Jul 26, 2020 Jul 26, 2020

Copy link to clipboard

Copied

LATEST

Thank you so much Thom that code make it working.

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