Skip to main content
Participant
July 23, 2020
Answered

Can I have a text field have a custom calculation AND still allow a user to enter custom content?

  • July 23, 2020
  • 1 reply
  • 2563 views

Hi! 

 

I've made a quotation form using Adobe acrobat form editor. 

I've set it up with four columns - product, quantity, cost per unit, and total cost. 

I've set up the fields so our sales team can select the product from a drop-down (options items) which automatically inserts the cost per unit that I inserted in the export value of the drop-down items.

 

This works really well - however, sometimes the cost per unit might need to be changed manually and I can't seem to figure out how to set the field to allow the user to enter custom text when needed. 

 

The script I'm using is:

event.value = this.getField('ProductRow1').value; 

I'm assuming I'll need to add something to this - but I'm no pro at Javascript and I'm not sure what! 

 

Thanks in advance!

This topic has been closed for replies.
Correct answer try67

Yes, it's possible, but it can get quite complicated, especially if the calculation depends on multiple fields, and they also have a calculated value. If it doesn't then you can use this:

 

if (event.source && event.source.name=="ProductRow1")

event.value = this.getField('ProductRow1').value;

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 23, 2020

Yes, it's possible, but it can get quite complicated, especially if the calculation depends on multiple fields, and they also have a calculated value. If it doesn't then you can use this:

 

if (event.source && event.source.name=="ProductRow1")

event.value = this.getField('ProductRow1').value;

iNeedArrays
Participating Frequently
July 20, 2022

Try67,  I am facing a similar issue as the original poster and hoping you can help. 

 

I am populating two text fields based on the selection from a dropdown menu. But mine is a bit more complicated. It looks like this:

Dropdown Menu (Field name:Course), Course Description (Field Name: Course Description), Price (Field Name: Price)

 

The Course Description field is using a Custom Calculation Script, what I believe is called an Array of Span objects within a Switch Statement with several Cases(drop down items) and several objects per array for the sake of formatting Rich text:

 

var drop = this.getField("Course").valueAsString;

event.target.richText = true;
event.target.multiline = true;

switch(drop){
case "ISO 9001:2015 Executive Overview - Virtual Instructor Lead Course":
var spans = new Array();
spans[0] = new Object();
spans[0].text = drop;

 

case "ISO/IEC 27001:2013 Executive Overview":
var spans2 = new Array();
spans2[0] = new Object();
spans2[0].text = drop;

 

event.richValue = spans;
break;

default:
event.value = "";}

 

and so on..

 

And my Course field has this Custom Validation script to populate the Price Field based on selection:

 

var f = this.getField("Price");
switch(event.value){

case "ISO 9001:2015 Executive Overview - Virtual Instructor Lead Course":
f.value = 1000;
break;

 

All of this is working well except when I try to enter custom text in the Course Description field. I can see the custom text I'm entering...but then it disappears when I click away from that text field. 

 

Do you know if my situation is possible to allow the custom calculation and custom text? 

 

Thank you

iNeedArrays
Participating Frequently
July 21, 2022

I don't understand. DO you want to reset the other field is "Other" is selected, or if it's not selected?

If the former, remove the if-condition. If the latter, replace

case "Other"

with the default-clause.


I want to reset the field (Course Description) if 'Other' is selected, but still allow for the user to enter custom text.

 

You say remove the if-condition in this case, but that would put me back to your first solution of removing the default clause. This does allow me to enter custom text when 'Other' is selected..but the end user would see the carry-over description if another item were selected first. They would then need to erase that text before typing in their own, which i am trying to avoid.