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

Check if there is an photo uploaded in an image field

Community Beginner ,
Nov 12, 2024 Nov 12, 2024

Copy link to clipboard

Copied

How can I check if a photo is uploaded in an image field using a script? I want to show it in a text field as a status.

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , Modern Acrobat , PDF , PDF forms

Views

203

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
1 ACCEPTED SOLUTION
Community Expert ,
Nov 12, 2024 Nov 12, 2024

Copy link to clipboard

Copied

That's exactly what my script does.  You need a trigger.  The mouseup action of the button is the trigger.  Calculation scripts only change when field values change.  An image added to a button field is not a value change.  What do you mean "prompt"?  If you insist on making this a custom calculation script in the text field you would change the script to the following (assuming "Button1" is the image field name):

var icn=this.getField("Button1").buttonGetIcon();
var status="Has image";
try{util.iconStreamFromIcon(icn)}catch(e){status="Does not have image."}
event.value=status;

You will still need to modify the mouseup action of the image field so the change happens immediately by adding this line of code to the mouse up action:

this.calculateNow();

View solution in original post

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 ,
Nov 12, 2024 Nov 12, 2024

Copy link to clipboard

Copied

In the mouse up action of the image you should this script:

event.target.buttonImportIcon();

Assuming the name of your text field is "Status", add the following script after the script above in the mouse up action of the button/image field:

var icn=event.target.buttonGetIcon();
var status="Has image";
try{util.iconStreamFromIcon(icn)}catch(e){status="Does not have image."}
this.getField("Status").value=status;

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 Beginner ,
Nov 12, 2024 Nov 12, 2024

Copy link to clipboard

Copied

I have tried to use this in a Calculate event of a text field to
automatically show the status but somehow it does not work immediately, you
need to make an input from another field to trigger it to calculate,,, what
I am trying to have is that it should immediately prompt in a text field
that a user has uploaded an image right after uploading an image field.

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 ,
Nov 12, 2024 Nov 12, 2024

Copy link to clipboard

Copied

That's exactly what my script does.  You need a trigger.  The mouseup action of the button is the trigger.  Calculation scripts only change when field values change.  An image added to a button field is not a value change.  What do you mean "prompt"?  If you insist on making this a custom calculation script in the text field you would change the script to the following (assuming "Button1" is the image field name):

var icn=this.getField("Button1").buttonGetIcon();
var status="Has image";
try{util.iconStreamFromIcon(icn)}catch(e){status="Does not have image."}
event.value=status;

You will still need to modify the mouseup action of the image field so the change happens immediately by adding this line of code to the mouse up action:

this.calculateNow();

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 Beginner ,
Nov 12, 2024 Nov 12, 2024

Copy link to clipboard

Copied

Thank you for that script. But, yes, it does when triggered using Mouse Up.
What I am saying is is there a way that when you upload an image, my text
field will automatically show the status that there is an uploaded image. I
tried it i Calculate but its not working fine.

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 ,
Nov 12, 2024 Nov 12, 2024

Copy link to clipboard

Copied

Both of my scripts do exactly that.  One is a mouse up event in the button/image field.  The other is a calculation event in the text field.  Choose one or the other.  If you chose the calculation script you need to add a this.calculateNow() to the button/image script.  What do you mean "upload an image"? What do you want the text field to say?

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 Beginner ,
Nov 12, 2024 Nov 12, 2024

Copy link to clipboard

Copied

LATEST

Ow sorry, I get it now. I was just confused. But it's working like I want it. Thank you very much. The this.CalculateNow() made it work. 😊

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