在 Acrobat 中,我能否使数组中的字段成为必需字段,或者快速使多个字段 required/not 成为必需字段?
In Acrobat, can I make fields in an array required, or quickly make many fields required/not required?
我工作的实验室每年分发和评估一次能力测试,目前正在 Adobe Acrobat 中开发 PDF,以便我们以数字方式(而不是通过邮件)收集结果。我对 JavaScript 及其在 Acrobat 中的使用完全陌生,但到目前为止,我已经设法从很棒的论坛答案中拼凑出一个工作表格!
表单中有多个测试,每个测试可能有多种执行测试的方法。为确保填写每个字段,我们包含了基于单选按钮或下拉选择的编码。
var CDA = getField("CDA").value
var CDA1 = getField("CDA Unheated Sample 15");
var CDA2 = getField("CDA Unheated Sample 16");
var CDA3 = getField("CDA Unheated Sample 17");
var CDA4 = getField("CDA Unheated Sample 18");
var CDA5 = getField("CDA Unheated Sample 19");
var CDA6 = getField("CDA Unheated Sample 20");
var CDA7 = getField("CDA Unheated Sample 21");
var CDA8 = getField("CDA Unheated Sample 22");
var CDA9 = getField("CDA Unheated Positive Control");
var CDA10 = getField("CDA Unheated Negative Control");
var CDA11 = getField("CDA Interp Sample 15");
var CDA12 = getField("CDA Interp Sample 16");
var CDA13 = getField("CDA Interp Sample 17");
var CDA14 = getField("CDA Interp Sample 18");
var CDA15 = getField("CDA Interp Sample 19");
var CDA16 = getField("CDA Interp Sample 20");
var CDA17 = getField("CDA Interp Sample 21");
var CDA18 = getField("CDA Interp Sample 22");
var CDA19 = getField("CDA Interp Positive Control");
var CDA20 = getField("CDA Interp Negative Control");
var CDA21 = getField("Date Analyzed_2");
var CDA22 = getField("Sample temperature_3");
if ( CDA == "Not Performed") {
CDA1.required = false;
CDA2.required = false;
CDA3.required = false;
CDA4.required = false;
CDA5.required = false;
CDA6.required = false;
CDA7.required = false;
CDA8.required = false;
CDA9.required = false;
CDA10.required = false;
CDA11.required = false;
CDA12.required = false;
CDA13.required = false;
CDA14.required = false;
CDA15.required = false;
CDA16.required = false;
CDA17.required = false;
CDA18.required = false;
CDA19.required = false;
CDA20.required = false;
CDA21.required = false;
CDA22.required = false;
}
else if (CDA == "Performed") {
CDA1.required = true;
CDA2.required = true;
CDA3.required = true;
CDA4.required = true;
CDA5.required = true;
CDA6.required = true;
CDA7.required = true;
CDA8.required = true;
CDA9.required = true;
CDA10.required = true;
CDA11.required = true;
CDA12.required = true;
CDA13.required = true;
CDA14.required = true;
CDA15.required = true;
CDA16.required = true;
CDA17.required = true;
CDA18.required = true;
CDA19.required = true;
CDA20.required = true;
CDA21.required = true;
CDA22.required = true;
}
虽然上面的方法有效,但感觉很笨拙,并且是 Performed/Not 执行方法的较短代码之一。对于一些使用多种方法的测试,我有 3-5 个条件发生,需要每次更改所有 'required' 字段(试图防止白痴)。
有没有更有效的方法来一次更改很多字段的 'required' 状态?可不可以把所有可能需要调用的字段都存储在一个数组中,然后快速改变数组中所有字段的'required'状态?更像是:
var CDA = getField("CDA").value
var CDA_array = [getField("CDA Unheated Sample 15"),
getField("CDA Unheated Sample 16"),
getField("CDA Unheated Sample 17"),
getField("CDA Unheated Sample 18"),
getField("CDA Unheated Sample 19"),
getField("CDA Unheated Sample 20"),
getField("CDA Unheated Sample 21"),
getField("CDA Unheated Sample 22"),
getField("CDA Unheated Positive Control"),
getField("CDA Unheated Negative Control"),
getField("CDA Interp Sample 15"),
getField("CDA Interp Sample 16"),
getField("CDA Interp Sample 17"),
getField("CDA Interp Sample 18"),
getField("CDA Interp Sample 19"),
getField("CDA Interp Sample 20"),
getField("CDA Interp Sample 21"),
getField("CDA Interp Sample 22"),
getField("CDA Interp Positive Control"),
getField("CDA Interp Negative Control"),
getField("Date Analyzed_2"),
getField("Sample temperature_3")];
if (CDA == "Not Performed") {
CDA_array.required = false;
}
else if (CDA == "Performed") {
CDA_array.required = true;
}
这是可以做到的,还是我应该接受我们的第一个工作版本?我目前处于远程状态,直到下周才能使用完整的 Acrobat 许可证访问我们的工作站,因此我无法尝试第二个代码块以查看会发生什么。提前感谢您阅读这部古老的大小说,以及您可以提供的任何帮助或见解!
如果您将字段重命名为带点符号的分层字段,则可以在 parent 上设置所需的 属性。像这样命名您的字段...
CDA.Unheated 样本 15
CDA.Unheated 样本 16
CDA.Unheated 样本 17
CDA.Interp 阳性对照
等...
您的代码将变为...
this.getField("CDA").required = true;
或
this.getField("CDA").required = false;
CDA 是 parent 字段。 children 然后继承所需的 属性.
我工作的实验室每年分发和评估一次能力测试,目前正在 Adobe Acrobat 中开发 PDF,以便我们以数字方式(而不是通过邮件)收集结果。我对 JavaScript 及其在 Acrobat 中的使用完全陌生,但到目前为止,我已经设法从很棒的论坛答案中拼凑出一个工作表格!
表单中有多个测试,每个测试可能有多种执行测试的方法。为确保填写每个字段,我们包含了基于单选按钮或下拉选择的编码。
var CDA = getField("CDA").value
var CDA1 = getField("CDA Unheated Sample 15");
var CDA2 = getField("CDA Unheated Sample 16");
var CDA3 = getField("CDA Unheated Sample 17");
var CDA4 = getField("CDA Unheated Sample 18");
var CDA5 = getField("CDA Unheated Sample 19");
var CDA6 = getField("CDA Unheated Sample 20");
var CDA7 = getField("CDA Unheated Sample 21");
var CDA8 = getField("CDA Unheated Sample 22");
var CDA9 = getField("CDA Unheated Positive Control");
var CDA10 = getField("CDA Unheated Negative Control");
var CDA11 = getField("CDA Interp Sample 15");
var CDA12 = getField("CDA Interp Sample 16");
var CDA13 = getField("CDA Interp Sample 17");
var CDA14 = getField("CDA Interp Sample 18");
var CDA15 = getField("CDA Interp Sample 19");
var CDA16 = getField("CDA Interp Sample 20");
var CDA17 = getField("CDA Interp Sample 21");
var CDA18 = getField("CDA Interp Sample 22");
var CDA19 = getField("CDA Interp Positive Control");
var CDA20 = getField("CDA Interp Negative Control");
var CDA21 = getField("Date Analyzed_2");
var CDA22 = getField("Sample temperature_3");
if ( CDA == "Not Performed") {
CDA1.required = false;
CDA2.required = false;
CDA3.required = false;
CDA4.required = false;
CDA5.required = false;
CDA6.required = false;
CDA7.required = false;
CDA8.required = false;
CDA9.required = false;
CDA10.required = false;
CDA11.required = false;
CDA12.required = false;
CDA13.required = false;
CDA14.required = false;
CDA15.required = false;
CDA16.required = false;
CDA17.required = false;
CDA18.required = false;
CDA19.required = false;
CDA20.required = false;
CDA21.required = false;
CDA22.required = false;
}
else if (CDA == "Performed") {
CDA1.required = true;
CDA2.required = true;
CDA3.required = true;
CDA4.required = true;
CDA5.required = true;
CDA6.required = true;
CDA7.required = true;
CDA8.required = true;
CDA9.required = true;
CDA10.required = true;
CDA11.required = true;
CDA12.required = true;
CDA13.required = true;
CDA14.required = true;
CDA15.required = true;
CDA16.required = true;
CDA17.required = true;
CDA18.required = true;
CDA19.required = true;
CDA20.required = true;
CDA21.required = true;
CDA22.required = true;
}
虽然上面的方法有效,但感觉很笨拙,并且是 Performed/Not 执行方法的较短代码之一。对于一些使用多种方法的测试,我有 3-5 个条件发生,需要每次更改所有 'required' 字段(试图防止白痴)。
有没有更有效的方法来一次更改很多字段的 'required' 状态?可不可以把所有可能需要调用的字段都存储在一个数组中,然后快速改变数组中所有字段的'required'状态?更像是:
var CDA = getField("CDA").value
var CDA_array = [getField("CDA Unheated Sample 15"),
getField("CDA Unheated Sample 16"),
getField("CDA Unheated Sample 17"),
getField("CDA Unheated Sample 18"),
getField("CDA Unheated Sample 19"),
getField("CDA Unheated Sample 20"),
getField("CDA Unheated Sample 21"),
getField("CDA Unheated Sample 22"),
getField("CDA Unheated Positive Control"),
getField("CDA Unheated Negative Control"),
getField("CDA Interp Sample 15"),
getField("CDA Interp Sample 16"),
getField("CDA Interp Sample 17"),
getField("CDA Interp Sample 18"),
getField("CDA Interp Sample 19"),
getField("CDA Interp Sample 20"),
getField("CDA Interp Sample 21"),
getField("CDA Interp Sample 22"),
getField("CDA Interp Positive Control"),
getField("CDA Interp Negative Control"),
getField("Date Analyzed_2"),
getField("Sample temperature_3")];
if (CDA == "Not Performed") {
CDA_array.required = false;
}
else if (CDA == "Performed") {
CDA_array.required = true;
}
这是可以做到的,还是我应该接受我们的第一个工作版本?我目前处于远程状态,直到下周才能使用完整的 Acrobat 许可证访问我们的工作站,因此我无法尝试第二个代码块以查看会发生什么。提前感谢您阅读这部古老的大小说,以及您可以提供的任何帮助或见解!
如果您将字段重命名为带点符号的分层字段,则可以在 parent 上设置所需的 属性。像这样命名您的字段...
CDA.Unheated 样本 15
CDA.Unheated 样本 16
CDA.Unheated 样本 17
CDA.Interp 阳性对照
等...
您的代码将变为...
this.getField("CDA").required = true;
或
this.getField("CDA").required = false;
CDA 是 parent 字段。 children 然后继承所需的 属性.