如何使用 XFA/Livecycle 从对话框保存用户输入的结果
How to save results of user input from a dialog box with XFA/Livecycle
我在 LiveCycle ES4 中开发了一个表单,然后制作了一个 Adobe Reader 兼容的 PDF,需要一些帮助。表单的第一页本质上是一个具有预定字段的数据集。在第二页上有一个按钮,可以获取从第一页输入的所有数据,并根据该数据生成书面报告。
但是,并不是生成报告所需的所有信息都包含在第一页上,而且它是一个标准化的数据集,所以我无法添加额外的字段。我的解决方案是使用弹出对话框从用户那里收集 4 条信息,它使用两个下拉框和两个自由文本字段(目前)。我使用了一个在网上找到的工具来帮助我构建对话框(非常感谢 BR001 创建它),现在我需要知道如何将用户的输入存储为一个变量,以便在 'Generate report' 按钮,我的代码在这里生成书面报告。
我是 JavaScript 的初学者,到目前为止,我只知道创建此表单所需的知识。我怎样才能做到这一点?谢谢!
这是我的对话框代码:
function dialog()
{
var dialogDescriptor =
{
description:
{
name: "dailog1",
align_children: "align_distribute",
margin_width: 20,
margin_height: 20,
elements: [
{
type: "cluster",
item_id: "clu1",
align_children: "align_left",
alignment: "align_center",
name: "Enter location of evaluation:",
bold: true,
elements: [
{
type: "view",
align_children: "align_distribute",
elements: [
{
type: "static_text",
alignment: "align_center",
name: "State:",
},
{
width: 80,
height: 22,
type: "popup",
item_id: "pop1",
alignment: "align_center",
},
{
type: "static_text",
alignment: "align_center",
name: "County:",
},
{
width: 125,
height: 22,
type: "popup",
item_id: "pop2",
alignment: "align_center",
}
]
},
{
type: "view",
align_children: "align_left",
elements: [
{
type: "static_text",
name: "Place: (ex: Memorial Hermann Hospital Room 123)",
},
{
width: 385,
height: 22,
type: "edit_text",
item_id: "edi1",
}
]
}
]
},
{
type: "cluster",
align_children: "align_distribute",
name: "How do you want to refer to the subject?",
elements: [
{
width: 385,
height: 22,
type: "edit_text",
item_id: "edi2",
}
]
},
{
type: "ok_cancel",
alignment: "align_top",
ok_name: "Create Narrative",
}
]
},
initialize : function(dialog)
{
dialog.load({
"pop1": dialogObject.pop1,
"pop2": dialogObject.pop2,
"edi1": dialogObject.edi1,
"edi2": dialogObject.edi2,
});
},
validate : function(dialog)
{
//add validate code here
return true;
},
commit : function(dialog)
{
var elements = dialog.store();
dialogObject.pop1 = elements["pop1"];
dialogObject.pop2 = elements["pop2"];
dialogObject.edi1 = elements["edi1"];
dialogObject.edi2 = elements["edi2"];
},
"clu1" : function(dialog)
{
},
"pop1": function (dialog)
{
var lst1 = dialog.store()["pop1"];
for (var item in lst1)
{
if (lst1[item] > 0)
{
var selectedValue = item;
break;
}
}
if (selectedValue == "Alabama") {
dialog.load(
{
"pop2": ({"Autauga": 1, "Baldwin": -1, "Barbour": -2, "Bibb": -3, "Blount": -4, "Bullock": -5, "Butler": -6, "Calhoun": -7, "Chambers": -8, "Cherokee": -9, "Chilton": -10, "Choctaw": -11, "Clarke": -12, "Clay": -13, "Cleburne": -14, "Coffee": -15, "Colbert": -16, "Conecuh": -17, "Coosa": -18, "Covington": -19, "Crenshaw": -20, "Cullman": -21, "Dale": -22, "Dallas": -23, "DeKalb": -24, "Elmore": -25, "Escambia": -26, "Etowah": -27, "Fayette": -28, "Franklin": -29, "Geneva": -30, "Greene": -31, "Hale": -32, "Henry": -33, "Houston": -34, "Jackson": -35, "Jefferson": -36, "Lamar": -37, "Lauderdale": -38, "Lawrence": -39, "Lee": -40, "Limestone": -41, "Lowndes": -42, "Macon": -43, "Madison": -44, "Marengo": -45, "Marion": -46, "Marshall": -47, "Mobile": -48, "Monroe": -49, "Montgomery": -50, "Morgan": -51, "Perry": -52, "Pickens": -53, "Pike": -54, "Randolph": -55, "Russell": -56, "St. Clair": -57, "Shelby": -58, "Sumter": -59, "Talladega": -60, "Tallapoosa": -61, "Tuscaloosa": -62, "Walker": -63, "Washington": -64, "Wilcox": -65, "Winston": -66})
});
}
else if (selectedValue == "Alaska") {
dialog.load(
{
"pop2": ({"Aleutians East": 1, "Aleutians West": -1, "Anchorage": -2, "Bethel": -3, "Bristol Bay": -4, "Denali": -5, "Dillingham": -6, "Fairbanks North Star": -7, "Haines": -8, "Juneau": -9, "Kenai Peninsula": -10, "Ketchikan Gateway": -11, "Kodiak Island": -12, "Lake And Peninsula": -13, "Matanuska-Susitna": -14, "Nome": -15, "North Slope": -16, "Northwest Arctic": -17, "Prince of Wales-Outer Ketchikan": -18, "Sitka": -19, "Skagway": -20, "Southeast Fairbanks": -21, "Valdez-Cordova": -22, "Wade Hampton": -23, "Wrangell": -24, "Yakutat": -25})
});
}
},
"pop2" : function(dialog)
{
},
"edi1" : function(dialog)
{
},
"edi2" : function(dialog)
{
},
};
var dialogObject =
{
pop1: ({' ':1, Alabama:-1, Alaska:-1, Arizona:-2, Arkansas:-3, California:-4, Colorado:-5, Connecticut:-6, Delaware:-7, Florida:-8, Georgia:-9, Hawaii:-10, Idaho:-11, Illinois:-12, Indiana:-13, Iowa:-14, Kansas:-15, Kentucky:-16, Louisiana:-17, Maine:-18, Maryland:-19, Massachusetts:-20, Michigan:-21, Minnesota:-22, Mississippi:-23, Missouri:-24, Montana:-25, Nebraska:-26, Nevada:-27, 'New Hampshire':-28, 'New Jersey':-29, 'New Mexico':-30, 'New York':-31, 'North Carolina':-32, 'North Dakota':-33, Ohio:-34, Oklahoma:-35, Oregon:-36, Pennsylvania:-37, 'Rhode Island':-38, 'South Carolina':-39, 'South Dakota':-40, Tennessee:-41, Texas:-42, Utah:-43, Vermont:-44, Virginia:-45, Washington:-46, 'West Virginia':-47, Wisconsin:-48, Wyoming:-49}),
pop2: ({}),
edi1: "",
edi2: "SUBJECT",
execDialog: function() { return app.execDialog(dialogDescriptor); },
selectedItem: function (control) { if (typeof (control) === "string") { control = this[control]; } for (var item in control) { if (typeof (control[item]) === "object") { var r = this.selectedItem(control[item]);if (r !== undefined){ return r; }} else { if (control[item] > 0){return control[item];}}}} };
return dialogObject;
}
var d = dialog();
d.execDialog();
console.println(d.pop1.toSource());
console.println(d.pop2.toSource());
console.println(d.edi1);
console.println(d.edi2);
将'function dialog()'-代码放入sciptingobject
并将脚本对象重命名为 'Main'.
然后注释掉:
// var d = dialog();
和
// d.execDialog();
在按钮点击事件中写入:
var d = Main.dialog();
d.execDialog();
Textfield1.rawValue = d.edi1;
对于下拉列表的索引 pop1/pop2:
Textfield2.rawValue = d.selectedItem("pop1");
希望对您有所帮助...
清洁工
我在 LiveCycle ES4 中开发了一个表单,然后制作了一个 Adobe Reader 兼容的 PDF,需要一些帮助。表单的第一页本质上是一个具有预定字段的数据集。在第二页上有一个按钮,可以获取从第一页输入的所有数据,并根据该数据生成书面报告。
但是,并不是生成报告所需的所有信息都包含在第一页上,而且它是一个标准化的数据集,所以我无法添加额外的字段。我的解决方案是使用弹出对话框从用户那里收集 4 条信息,它使用两个下拉框和两个自由文本字段(目前)。我使用了一个在网上找到的工具来帮助我构建对话框(非常感谢 BR001 创建它),现在我需要知道如何将用户的输入存储为一个变量,以便在 'Generate report' 按钮,我的代码在这里生成书面报告。
我是 JavaScript 的初学者,到目前为止,我只知道创建此表单所需的知识。我怎样才能做到这一点?谢谢!
这是我的对话框代码:
function dialog()
{
var dialogDescriptor =
{
description:
{
name: "dailog1",
align_children: "align_distribute",
margin_width: 20,
margin_height: 20,
elements: [
{
type: "cluster",
item_id: "clu1",
align_children: "align_left",
alignment: "align_center",
name: "Enter location of evaluation:",
bold: true,
elements: [
{
type: "view",
align_children: "align_distribute",
elements: [
{
type: "static_text",
alignment: "align_center",
name: "State:",
},
{
width: 80,
height: 22,
type: "popup",
item_id: "pop1",
alignment: "align_center",
},
{
type: "static_text",
alignment: "align_center",
name: "County:",
},
{
width: 125,
height: 22,
type: "popup",
item_id: "pop2",
alignment: "align_center",
}
]
},
{
type: "view",
align_children: "align_left",
elements: [
{
type: "static_text",
name: "Place: (ex: Memorial Hermann Hospital Room 123)",
},
{
width: 385,
height: 22,
type: "edit_text",
item_id: "edi1",
}
]
}
]
},
{
type: "cluster",
align_children: "align_distribute",
name: "How do you want to refer to the subject?",
elements: [
{
width: 385,
height: 22,
type: "edit_text",
item_id: "edi2",
}
]
},
{
type: "ok_cancel",
alignment: "align_top",
ok_name: "Create Narrative",
}
]
},
initialize : function(dialog)
{
dialog.load({
"pop1": dialogObject.pop1,
"pop2": dialogObject.pop2,
"edi1": dialogObject.edi1,
"edi2": dialogObject.edi2,
});
},
validate : function(dialog)
{
//add validate code here
return true;
},
commit : function(dialog)
{
var elements = dialog.store();
dialogObject.pop1 = elements["pop1"];
dialogObject.pop2 = elements["pop2"];
dialogObject.edi1 = elements["edi1"];
dialogObject.edi2 = elements["edi2"];
},
"clu1" : function(dialog)
{
},
"pop1": function (dialog)
{
var lst1 = dialog.store()["pop1"];
for (var item in lst1)
{
if (lst1[item] > 0)
{
var selectedValue = item;
break;
}
}
if (selectedValue == "Alabama") {
dialog.load(
{
"pop2": ({"Autauga": 1, "Baldwin": -1, "Barbour": -2, "Bibb": -3, "Blount": -4, "Bullock": -5, "Butler": -6, "Calhoun": -7, "Chambers": -8, "Cherokee": -9, "Chilton": -10, "Choctaw": -11, "Clarke": -12, "Clay": -13, "Cleburne": -14, "Coffee": -15, "Colbert": -16, "Conecuh": -17, "Coosa": -18, "Covington": -19, "Crenshaw": -20, "Cullman": -21, "Dale": -22, "Dallas": -23, "DeKalb": -24, "Elmore": -25, "Escambia": -26, "Etowah": -27, "Fayette": -28, "Franklin": -29, "Geneva": -30, "Greene": -31, "Hale": -32, "Henry": -33, "Houston": -34, "Jackson": -35, "Jefferson": -36, "Lamar": -37, "Lauderdale": -38, "Lawrence": -39, "Lee": -40, "Limestone": -41, "Lowndes": -42, "Macon": -43, "Madison": -44, "Marengo": -45, "Marion": -46, "Marshall": -47, "Mobile": -48, "Monroe": -49, "Montgomery": -50, "Morgan": -51, "Perry": -52, "Pickens": -53, "Pike": -54, "Randolph": -55, "Russell": -56, "St. Clair": -57, "Shelby": -58, "Sumter": -59, "Talladega": -60, "Tallapoosa": -61, "Tuscaloosa": -62, "Walker": -63, "Washington": -64, "Wilcox": -65, "Winston": -66})
});
}
else if (selectedValue == "Alaska") {
dialog.load(
{
"pop2": ({"Aleutians East": 1, "Aleutians West": -1, "Anchorage": -2, "Bethel": -3, "Bristol Bay": -4, "Denali": -5, "Dillingham": -6, "Fairbanks North Star": -7, "Haines": -8, "Juneau": -9, "Kenai Peninsula": -10, "Ketchikan Gateway": -11, "Kodiak Island": -12, "Lake And Peninsula": -13, "Matanuska-Susitna": -14, "Nome": -15, "North Slope": -16, "Northwest Arctic": -17, "Prince of Wales-Outer Ketchikan": -18, "Sitka": -19, "Skagway": -20, "Southeast Fairbanks": -21, "Valdez-Cordova": -22, "Wade Hampton": -23, "Wrangell": -24, "Yakutat": -25})
});
}
},
"pop2" : function(dialog)
{
},
"edi1" : function(dialog)
{
},
"edi2" : function(dialog)
{
},
};
var dialogObject =
{
pop1: ({' ':1, Alabama:-1, Alaska:-1, Arizona:-2, Arkansas:-3, California:-4, Colorado:-5, Connecticut:-6, Delaware:-7, Florida:-8, Georgia:-9, Hawaii:-10, Idaho:-11, Illinois:-12, Indiana:-13, Iowa:-14, Kansas:-15, Kentucky:-16, Louisiana:-17, Maine:-18, Maryland:-19, Massachusetts:-20, Michigan:-21, Minnesota:-22, Mississippi:-23, Missouri:-24, Montana:-25, Nebraska:-26, Nevada:-27, 'New Hampshire':-28, 'New Jersey':-29, 'New Mexico':-30, 'New York':-31, 'North Carolina':-32, 'North Dakota':-33, Ohio:-34, Oklahoma:-35, Oregon:-36, Pennsylvania:-37, 'Rhode Island':-38, 'South Carolina':-39, 'South Dakota':-40, Tennessee:-41, Texas:-42, Utah:-43, Vermont:-44, Virginia:-45, Washington:-46, 'West Virginia':-47, Wisconsin:-48, Wyoming:-49}),
pop2: ({}),
edi1: "",
edi2: "SUBJECT",
execDialog: function() { return app.execDialog(dialogDescriptor); },
selectedItem: function (control) { if (typeof (control) === "string") { control = this[control]; } for (var item in control) { if (typeof (control[item]) === "object") { var r = this.selectedItem(control[item]);if (r !== undefined){ return r; }} else { if (control[item] > 0){return control[item];}}}} };
return dialogObject;
}
var d = dialog();
d.execDialog();
console.println(d.pop1.toSource());
console.println(d.pop2.toSource());
console.println(d.edi1);
console.println(d.edi2);
将'function dialog()'-代码放入sciptingobject 并将脚本对象重命名为 'Main'.
然后注释掉:
// var d = dialog();
和
// d.execDialog();
在按钮点击事件中写入:
var d = Main.dialog();
d.execDialog();
Textfield1.rawValue = d.edi1;
对于下拉列表的索引 pop1/pop2:
Textfield2.rawValue = d.selectedItem("pop1");
希望对您有所帮助... 清洁工