• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Jul 22, 2020 Jul 22, 2020

Copy link to clipboard

Copied

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!

TOPICS
PDF forms

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 23, 2020 Jul 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;

Votes

Translate

Translate
Community Expert ,
Jul 23, 2020 Jul 23, 2020

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 29, 2020 Jul 29, 2020

Copy link to clipboard

Copied

That worked perfectly! Thanks heaps! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

It's happening because of the default case in your switch, which is a "catch all" for all other values, such as the ones you enter manually into the field. Just remove the line of code after it:

event.value = "";

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

That makes sense. It does work by removing that line of code, but leaves behind the previously selected description there until you erase it and/or replace with custom text. Is it too complicated to get around this somehow? Perhaps an If statement to erase the description box based upon a particular selection?

 

Thanks Try

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

Sure. You can just add it as another case in the switch.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

I tried it every way I could think of. 

 

case "Other":
if(event.value != "Other") {this.resetForm("Course Description");
}

 

It does effectively reset the field but reverts to not allowing me to enter custom text. Perhaps my newly added line is continuously telling the form to reset that field while I have 'Other' selected, making custom text impossible?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

If you want manual entry in text field, instead of custom calculation script in text field adapt code and move it to dropdown field as 'validation' script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

Nesa, 

 

Man I been troubleshooting it every way I can think of. I did take the calculation script from the text field and moved it to the validation script of the dropdown. 

 

I tried several ways of adapting including just changing the field reference name. Here's what I have and now the dropdown is not working at all..do you see anything glaring? In this text below, the only change I made was the field reference. I changed it from Course(dropdown field) to Course Description (text field).

 

var drop = this.getField("Course Description").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;

spans[1] = new Object();
spans[1].text = "\nCourse Duration: 0.5 Day Course Code: QMS-0100-VIL \n\n";
spans[1].bold;
spans[1].textSize = 9;

spans[2] = new Object();
spans[2].text = "In this course, you will learn an overview of the structure and requirements of an effective Quality Management System (QMS) and gain an understanding of the ISO 9001 key terms, definitions and the ISO standardized high level structure. You’ll also learn how Management will be auditing and how the Management Review provides a strong foundation for the QMS.\n\n";

default:
event.value = "";}

Thank you 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

You need to use it like this:

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

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

spans[1] = new Object();
spans[1].text = "\nCourse Duration: 0.5 Day Course Code: QMS-0100-VIL \n\n";
spans[1].fontWeight = 700;
spans[1].textSize = 9;

spans[2] = new Object();
spans[2].text = "In this course, you will learn an overview of the structure and requirements of an effective Quality Management System (QMS) and gain an understanding of the ISO 9001 key terms, definitions and the ISO standardized high level structure. You’ll also learn how Management will be auditing and how the Management Review provides a strong foundation for the QMS.\n\n";
drop.richValue = spans;
break;

default:
drop.value = "";}

For bold text use fontWeight, around 500 is normal text and around 700 is bold.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

LATEST

You're doing gods work, Nesa. It works, thank you.

 

How did you know it was necessary to make those changes. It looks like you left off the ValueAsString and changed the switch from drop to event.value? Does the code need to be different because it is now a validation script rather than a calculation?

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines