简体   繁体   English

更改一个字段会导致其他带前缀的字段更改-Adobe Acrobat Standard DC

[英]Changing one field causes other prefixed fields to change - Adobe Acrobat Standard DC

There are two fields in my form that changes when I insert text/number in other fields, why? 当我在其他字段中插入文本/数字时,表单中的两个字段会更改,为什么? They are not connected, for instance if I write my full name in a requested field (refering to the taken screenshot), it changes two fields "Fratrukket Rabatt (Discount price)" and "Total pris (total price)". 它们没有连接,例如,如果我在请求的字段中输入我的全名(请参阅所截取的屏幕截图),它将更改两个字段“ Fratrukket Rabatt(折扣价)”和“ Total pris(总价)”。

Fratrukket Rabatt (Discount price): Calculates the total discount Fratrukket Rabatt(折扣价):计算总折扣

// Get first value as number 
var v1 = +getField("Rabatt i prosent").value;

// Get second value as number 
var v2 = +getField("Total pris").value;

// Calculate the result
event.value = (v1 / 100) * v2; 

Total pris (total price): Calculates the total price substracting discount 总价格(总价):计算总价格减去折扣

// Get first value as number 
var viva1 = +getField("Pris per dekk").value;

// Get second value as number 
var viva2 = +getField("Antall dekk").value;

// Get third value as number 
var viva3 = +getField("Pris på arbeid").value;

// Get fourth value as number 
var viva4 = +getField("Fratrukket Rabatt").value;

// Calculate the result
event.value = ((viva1 * viva2) + viva3) - viva4;  

Is this a common problem, please help. 这是一个常见问题,请帮忙。

在此处输入图片说明

This is absolutely correct behavior, you encounter. 您遇到的这是绝对正确的行为。

Having a look at the Acrobat JavaScript documentation (part of the Acrobat SDK documentation, downloadable from the Adobe website), there is an explication and a diagram of the field event sequence. 查看Acrobat JavaScript文档(Acrobat SDK文档的一部分,可从Adobe网站下载),其中提供了现场事件序列的说明和图表。 Relevant for our issue is that the Calculate event is part of that sequence, and whenever a field value is changed, the complete Calculation sequence gets executed. 与我们的问题相关的是,Calculate事件是该序列的一部分,并且只要更改字段值,就会执行完整的Calculation序列。 So, if you have some default values, and some calculations using them, the calculated field values get recalculated. 因此,如果您有一些默认值以及使用它们的一些计算,则将重新计算计算出的字段值。

Now, there is, however, quite a bit of a confusion in the logic itself, and there is little chance to get reliable results to begin with. 但是,现在,逻辑本身存在很多混乱,并且几乎没有机会获得可靠的结果。

First and foremost, it is considered Best Practice to consolidate all calculations (of a calculation chain) into one single script, and either attach it to the last result field of the calculation chain, or an invisible, read-only field which is otherwise not involved in anything (the field event sequence is the reason why this works). 首先,最好的做法是将(计算链的)所有计算整合到一个脚本中,或者将其附加到计算链的最后一个结果字段,或者将其附加到不可见的只读字段(否则不是)涉及任何事物(现场事件序列是其起作用的原因)。

Based on what can be concluded from the example, your script in the Total Pris field could look like this: 根据示例可以得出的结论,您在Total Pris字段中的脚本如下所示:

Note that, in fact, there is a logical flaw in the calculation, because the discount relies on the grand total which is calculated after the discount gets calculated. 注意,实际上,在计算中存在逻辑缺陷,因为折扣依赖于在计算折扣之后计算的总计。

var deckprice = this.getField("Pris per dekk").value * this.getField("Antall dekk").value ;
var subtotal = deckprice + this.getField("Pris på arbeid").value*1 ;
var discount = subtotal * this.getField("Rabatt i prosent").value / 100 ;
var grandtotal = subtotal - discount ;

this.getField("Fratrukket Rabatt").value = discount ;
event.value = grandtotal ;

And that should do it. 那应该做到的。

If you are using this calculation in an independent field (not in the "Total Pris" field), you would change the last line to 如果您在独立字段(而不是“总价格”字段)中使用此计算,则应将最后一行更改为

this.getField("Total Pris").value = grandtotal ;

So much for the calculation. 计算就这么多。

Another suggestion (well, it is a bit of a pet peeve of mine…): I know that automatic field recognition in Acrobat is very convenient. 另一个建议(嗯,这有点像我的烦恼……):我知道Acrobat中的自动场识别非常方便。 However, the resulting field names are not very useful, and (more important) it prevents the user from doing a serious analysis of the form, which then leads to logical errors. 但是,结果字段名称不是很有用,并且(更重要的是)它防止用户对表单进行认真的分析,从而导致逻辑错误。

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

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