简体   繁体   English

Adobe Acrobat Pro DC自定义计算脚本建议

[英]Adobe Acrobat Pro DC custom calculation script advice

I'm trying to create a form with: 我正在尝试使用以下方法创建表单:

  1. a series of numerators and denominators to calculate 一系列分子和分母来计算
  2. if the field is left blank, it is not included in the calculation 如果该字段留为空白,则不包括在计算中
  3. the calculation to be updated in real time, and not wait for each field to have a number in it before it calculates. 该计算将实时更新,而不必等待每个字段中都有一个数字才可以进行计算。

This is the only calculation in the form, so changing the calculation order is not used. 这是表格中唯一的计算,因此不使用更改计算顺序。 In the document javascript, I have 在文档javascript中,我有

this.calculateNow();

and in the custom calculation script for the field, I have 在该字段的自定义计算脚本中,

(function () { 

var v1 = +getField("Text1").value;
var v2 = +getField("Text2").value;
var v3 = +getField("Text3").value;
var v4 = +getField("Text4").value;
var v5 = +getField("Text5").value;
var v6 = +getField("Text6").value;
var v7 = +getField("Text7").value;
var v8 = +getField("Text8").value;
var v9 = +getField("Text9").value;
var v10 = +getField("Text10").value;

event.value = (v2 * v4 * v6 * v8 * v10) !== 0 ? ((v1 * v3 * v5 * v7 * v9) / (v2 * v4 * v6 * v8 * v10)) : "";
})();

The issues I'm having: 我遇到的问题:

  1. that the calculation does not calculate in real time 该计算不能实时计算
  2. all fields still have to be entered for the calculation to occur. 为了进行计算,仍然必须输入所有字段。
  3. if zero is entered, the calculation will not run. 如果输入零,则该计算将不会运行。

Your code is a bit repetitive. 您的代码有点重复。 You may use an array containing the field ids: 您可以使用包含字段ID的数组:

const fields = Array.from({length:10}, (_,i)=>"Text"+(i+1));

Then we can map the fields to their value and use the or operator to fill unset fields: 然后,我们可以将字段映射到它们的值,然后使用or运算符填充未设置的字段:

const values = fields.map( f => +getField(f).value || 1 );

That array then can be reduced to a certain value, eg with mutliplication: 然后可以将该数组减小为某个值,例如使用多乘法:

const result = values.reduce((a,b) => a*b)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM