Loaded image in Image field makes Text field visible + required

Community Beginner ,
Sep 11, 2018

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:

  • If image is inserted into Image Field, the text field is made visible and required
  • If no image is inserted into Image Field, the text field remains hidden
  • If image is cleared from the Image Field, the text field becomes hidden and not required

Thank you kindly in advance for your help.

Tim

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

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 = "";

 

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

265

Likes

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

Loaded image in Image field makes Text field visible + required

Community Beginner ,
Sep 11, 2018

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:

  • If image is inserted into Image Field, the text field is made visible and required
  • If no image is inserted into Image Field, the text field remains hidden
  • If image is cleared from the Image Field, the text field becomes hidden and not required

Thank you kindly in advance for your help.

Tim

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

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 = "";

 

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

266

Likes

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
Sep 11, 2018 0
Adobe Community Professional ,
Sep 11, 2018

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.

Likes

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
Reply
Loading...
Sep 11, 2018 1
Community Beginner ,
Sep 11, 2018

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.

Likes

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
Reply
Loading...
Sep 11, 2018 0
Adobe Community Professional ,
Sep 11, 2018

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 = "";

 

}

Likes

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
Reply
Loading...
Sep 11, 2018 2
Adobe Community Professional ,
Sep 11, 2018

Copy link to clipboard

Copied

I had to fix a typo in my previous reply, so be sure to look at the latest version.

Likes

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
Reply
Loading...
Sep 11, 2018 0
Community Beginner ,
Sep 11, 2018

Copy link to clipboard

Copied

That code worked a treat, thanks so George_Johnson​ for your timely help. It is very much appreciated.

Likes

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
Reply
Loading...
Sep 11, 2018 0
Community Beginner ,
Sep 11, 2018

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

Likes

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
Reply
Loading...
Sep 11, 2018 0
Adobe Community Professional ,
Sep 12, 2018

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;

Likes

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
Reply
Loading...
Sep 12, 2018 2
Community Beginner ,
Sep 12, 2018

Copy link to clipboard

Copied

Wow, thanks for the great help George_Johnson​. It was spot-on, worked a treat!

Likes

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
Reply
Loading...
Sep 12, 2018 0