Skip to main content
Participating Frequently
October 30, 2024
Answered

How can I allow pre-programmed text to be user editable?

  • October 30, 2024
  • 2 replies
  • 618 views

Hi All,

I have a document where I've added JavaScript to a dropdown which populates text to an associated textbox.  This works perfectly, HOWEVER, I need for the user to ba able to edit the pre-programmed text.  The text can be edited, but when anything else is done on the form (i.e. another programmed dropdown is selected, an image is imported, etc.), the edited text refreshes to the original pre-programmed text.

 

I'm using Acrobat Pro DC (2015).  The JavaScript is in the Custom Calculation box of the dropdown box.  The text appears in a textbox.

 

Here is a sample of the code:

var dropdownValue1 = this.getField("InspectionText0").value;

switch(dropdownValue1) {

case 1:
this.getField("inspection_image_text.0").value = "Roof leaks are probably the single most common roofing problems plaguing most homeowners. The leaks could be a result of many roof issues, such as broken shingles.";
break;

case 2:
this.getField("inspection_image_text.0").value = "Your roof has a reduced life expectancy. Living in an area where your roof is continuously exposed to ice and snow. When ice melts, it doesn’t run off fast enough since it melts at a slow rate. This can pass as stagnant water which penetrates underneath the roof and causes issues.. Even worse, during cold weather, the water that gets underneath can also freeze when temperatures drop.. When water freezes, it expands and pushes against the shingles, which leaves an opening that lets even more water in.";
break;

case 3:
this.getField("inspection_image_text.0").value = "If the sealant attaching your shingles wears off, it tends to loosen and break or come off completely. The sealant may be damaged by force of nature, rodents, or wear and tear. Depending on the age of your roof, shingles may start tearing off, which should be expected.";
break;

default:
this.getField("inspection_image_text.0").value = "";
break;
}

 

This topic has been closed for replies.
Correct answer PDF Automation Station

Remove your scripts from the dropdown and enter the following custom calculation script in any other text field:

if(event.source && event.source.name=="InspectionText0")
{
var dropdownValue1 = this.getField("InspectionText0").value;

switch(dropdownValue1) {

case 1:
this.getField("inspection_image_text.0").value = "Roof leaks are probably the single most common roofing problems plaguing most homeowners. The leaks could be a result of many roof issues, such as broken shingles.";
break;

case 2:
this.getField("inspection_image_text.0").value = "Your roof has a reduced life expectancy. Living in an area where your roof is continuously exposed to ice and snow. When ice melts, it doesn’t run off fast enough since it melts at a slow rate. This can pass as stagnant water which penetrates underneath the roof and causes issues.. Even worse, during cold weather, the water that gets underneath can also freeze when temperatures drop.. When water freezes, it expands and pushes against the shingles, which leaves an opening that lets even more water in.";
break;

case 3:
this.getField("inspection_image_text.0").value = "If the sealant attaching your shingles wears off, it tends to loosen and break or come off completely. The sealant may be damaged by force of nature, rodents, or wear and tear. Depending on the age of your roof, shingles may start tearing off, which should be expected.";
break;

default:
this.getField("inspection_image_text.0").value = "";
break;
}
}

My 3rd link explains how to do this.

2 replies

PDF Automation Station
Community Expert
Community Expert
October 30, 2024

Calculation scripts run every time any field value changes.  Validation scripts only run when the value of the field that contains them changes.  You should use a validation script.  You can also use a calculation script if you test which field made the change, and only run the script if it was the dropdown.  References:

https://pdfautomationstation.substack.com/p/calculation-vs-validation-scripts

https://pdfautomationstation.substack.com/p/calculation-vs-validation-scripts-eb5

https://pdfautomationstation.substack.com/p/another-method-for-calculation-vs

 

Participating Frequently
October 30, 2024

I appreciate your help.

 

I understand the difference actions produced by validation vs calculation.  The links you provided didn't really give me any clairity into the specifics of my issue. 

 

My dilemma is that I have selections in a dropdown, and upon the user choosing a selection, the associated textbox needs to populate immediately.  That works fine with the script that I posted, as long as its in custome calculation.  When the script is placed in custom validation, the textbox doesn't update until another selection has been made.  (yes, commit selected value immediately is checked)

 

Essentially, I need the textbox to update immediately upon a dropdown selection being made, and for that content to be editable, without reverting back to the original text.  Please excuse my ignorance on how, exactly to accomplish this (this is the first time I've had to do anything like this).  

PDF Automation Station
Community Expert
Community Expert
October 30, 2024

Remove your scripts from the dropdown and enter the following custom calculation script in any other text field:

if(event.source && event.source.name=="InspectionText0")
{
var dropdownValue1 = this.getField("InspectionText0").value;

switch(dropdownValue1) {

case 1:
this.getField("inspection_image_text.0").value = "Roof leaks are probably the single most common roofing problems plaguing most homeowners. The leaks could be a result of many roof issues, such as broken shingles.";
break;

case 2:
this.getField("inspection_image_text.0").value = "Your roof has a reduced life expectancy. Living in an area where your roof is continuously exposed to ice and snow. When ice melts, it doesn’t run off fast enough since it melts at a slow rate. This can pass as stagnant water which penetrates underneath the roof and causes issues.. Even worse, during cold weather, the water that gets underneath can also freeze when temperatures drop.. When water freezes, it expands and pushes against the shingles, which leaves an opening that lets even more water in.";
break;

case 3:
this.getField("inspection_image_text.0").value = "If the sealant attaching your shingles wears off, it tends to loosen and break or come off completely. The sealant may be damaged by force of nature, rodents, or wear and tear. Depending on the age of your roof, shingles may start tearing off, which should be expected.";
break;

default:
this.getField("inspection_image_text.0").value = "";
break;
}
}

My 3rd link explains how to do this.

Bernd Alheit
Community Expert
Community Expert
October 30, 2024

Use a script at validation of the dropdown.