Copy link to clipboard
Copied
Hi,
I am creating form in Acrobat Pro to allows users to insert images via the Image Field function. Once an image is inserted, a text field below is required to be filled in.
I have created a javascript code for a similar scenario involving checkboxes. However, I have been unable to locate the correct terminology to reference the Image Field. Below is the Javascript code for the checkbox scenario.
event.target.buttonImportIcon();
var showHide = event.target.isBoxChecked(0)?display.visible:display.hidden;
this.getField("Photo1_Caption").display = showHide;
if(event.target.value == "Yes") {
// console.println("Checked " + event.value);
this.getField("Photo1_Caption").required = true;
}
else {
// console.println("Not " + event.value);
this.getField("Photo1_Caption").required = false;
}
Using the above code as a guide, is it possible for some assistance to achieve the following end outcome please:
Thank you kindly in advance for your help.
Tim
Here's what I had in mind for the Mouse Up script of the image field:
// Prompt the user to select an icon source
event.target.buttonImportIcon();
var oIcon;
// Get a reference to the image caption field
var f_Caption = getField("Photo1_Caption");
// Attempt to determine if there's a non-blank icon
try {
// The next line will generate an error if there's no icon (image)
oIcon = util.iconStreamFromIcon(event.target.buttonGetIcon());
// Set caption field to visible and required
f_Caption.di
...Copy link to clipboard
Copied
One way to attempt to determine if an icon is blank is something like:
// Prompt the user to select an icon source
event.target.buttonImportIcon();
var oIcon;
try {
oIcon = util.iconStreamFromIcon(event.target.buttonGetIcon());
} catch (e) {
app.alert("Blank icon!");
}
The buttonImportIcon method has a return code that you can check as well. Once you think you know whether the icon is blank or not, it's a simple matter to control the text field.
Copy link to clipboard
Copied
Thanks George_Johnson​ for the reply. My modified code thanks to your input is below.
// Prompt the user to select an icon source
event.target.buttonImportIcon();
var oIcon;
try {
oIcon = util.iconStreamFromIcon(event.target.buttonGetIcon());
} catch (e) {
app.alert("Blank icon!");
}this.getField("Photo1_Caption").display = showHide;
if(event.target.value == "Yes") {
// console.println("Checked " + event.value);
this.getField("Photo1_Caption").required = true;
}
else {
// console.println("Not " + event.value);
this.getField("Photo1_Caption").required = false;
}
However, I am unsure of the correct values for the items shown in bold blue in the above code as they are for checkboxes. I have a very basic understanding of Javascript so apologies if I have missed an obvious step.
Thanks.
Copy link to clipboard
Copied
Here's what I had in mind for the Mouse Up script of the image field:
// Prompt the user to select an icon source
event.target.buttonImportIcon();
var oIcon;
// Get a reference to the image caption field
var f_Caption = getField("Photo1_Caption");
// Attempt to determine if there's a non-blank icon
try {
// The next line will generate an error if there's no icon (image)
oIcon = util.iconStreamFromIcon(event.target.buttonGetIcon());
// Set caption field to visible and required
f_Caption.display = display.visible;
f_Caption.required = true;
} catch (e) {
// It's a blank icon
// so set caption field to hidden and not required
// and clear the value
f_Caption.display = display.hidden;
f_Caption.required = false;
f.value = "";
}
Copy link to clipboard
Copied
I had to fix a typo in my previous reply, so be sure to look at the latest version.
Copy link to clipboard
Copied
That code worked a treat, thanks so George_Johnson​ for your timely help. It is very much appreciated.
Copy link to clipboard
Copied
Hi George_Johnson​, I came across one variable which I did not anticipate previously.
The form has a reset button for each image field to clear the image from the field. The concept is based on this article. The Javascript code for the Reset button is below.
this.resetForm();
this.getField("Photo1").buttonSetIcon(this.getField("Blank1").buttonGetIcon());
However, when this button is used, while the image is cleared, the code you posted previously don't return the Photo1_Caption field to a hidden and non-required state.
Is there a way to modify the code for Photo1 Image Field to allow for the function of the Reset button please?
Thanks for your patience and assistance.
Tim
Copy link to clipboard
Copied
Just add code like the following to the reset button code:
var f_Caption = getField("Photo1_Caption");
f_Caption.display = display.hidden;
f_Caption.required = false;
Copy link to clipboard
Copied
Wow, thanks for the great help George_Johnson​. It was spot-on, worked a treat!