Skip to main content
Known Participant
January 9, 2024
Question

Manually override calculation field

  • January 9, 2024
  • 2 replies
  • 1646 views

Hi All,

 

I have the following script in a field that pulls berth depths from another field

 

var allberths = {

"SCPT": "10.1",

"WBCT": "10.9",

"WHT4": "11.1",

"GLB1": "12.0",

"GLB2": "12.0",

"GLB7": "10.6",

"GLB8": "9.4",

"GOR1": "13.2",

"GOR2": "8.9",

"WAHEN": "4.6",

"ICCD": "11.0",

"FLTBASE": "8.0",

"CBOFF": "11.8",

"BANK1": "14.0",

"BANK2": "13.5",

"ATHOL BAY": "11.6",

};

 

var movementField = this.getField("MOVEMENT");

var fromField = this.getField("FROM");

var toField = this.getField("TO");

 

if (movementField.value === "SELECT ONE") {

event.value = "0.00";

} else if (movementField.value === "ARRIVAL" && fromField.value === "SEA" && toField.value === "SELECT ONE") {

event.value = "0.00";

else if (movementField.value === "DEPARTURE" && fromField.value === "SELECT ONE" && toField.value === "SEA") {

event.value = "0.00";

} else if (movementField.value === "ARRIVAL" && allberths[toField.value]) { event.value = allberths[toField.value];

} else if (movementField.value === "DEPARTURE" && allberths[fromField.value]) { event.value = allberths[fromField.value];

} else if (movementField.value === "REMOVAL" && allberths[toField.value]) { event.value = allberths[toField.value];

} else { event.value = "0.00";

}

 

 

I was going to put in an option called "other" in my table, but want to able to enter the depth value manually but not sure how to do it. Currently if I enter a value manually it just reverts back to the value from the table.

 

Thanks

LC

This topic has been closed for replies.

2 replies

Thom Parker
Adobe Expert
January 9, 2024

In order to override a calculation there as to be a way for the script to know not to set the value. And the opposite has to be true as well. The script needs to know that it needs to set the value.   

 

The simplest solution is use an indicator value. You mentioned using an "Ohter" value in something? Is this a form field? If so then selecting "Other" could be used to block the calculation so a manual value could be entered. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
January 10, 2024

Thanks,

 

Yep "Other" will be an option to select instead of the ones listed above. I have added "other": "", as the last line in my table above

 

and removed the 

 

else { event.value = "0.00";

 

as per Nesa's suggestion above. I think it now works as required, just need to do some more testing to be sure.

 

Thanks for your help.

Nesa Nurani
Adobe Expert
January 9, 2024

Remove last line:

else { event.value = "0.00";

}

Known Participant
January 10, 2024

Thanks for that

 

see my comments below - i think i now have it working the way I want.

Thom Parker
Adobe Expert
January 18, 2024

After a bit reading and playing etc I settled for the following

 

if (movementField.value == "SELECT ONE") {

event.value = "0.00";

} else if (movementField.value == "ARRIVAL" && fromField.value == "SEA" && toField.value == "SELECT ONE") {

event.value = "0.00";

} else if (movementField.value == "DEPARTURE" && fromField.value == "SELECT ONE" && toField.value == "SEA") {

event.value = "0.00";

} else if (fromField.value == "OTHER" || toField.value == "OTHER") {

event.rc = true;

} else if (movementField.value == "ARRIVAL" && allberths[toField.value]) {

event.value = allberths[toField.value];

} else if (movementField.value == "DEPARTURE" && allberths[fromField.value]) {

event.value = allberths[fromField.value];

} else if (movementField.value == "REMOVAL" && allberths[toField.value]) {

event.value = allberths[toField.value];

} else { event.value = "0.00";

}

 

this seems to be allowing the user to manually enter their own value when "Other" is selected. 


Actually, event.rc should be set to false. 

You're code works, not because the calculation is being blocked, but because no value is being returned to event.value, which works out to about the same thing. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often