Skip to main content
Participant
August 27, 2020
Answered

Creating a disappearing Add Image Button

  • August 27, 2020
  • 3 replies
  • 930 views

Hello there,

 

I'm trying to create a form that has a labeled image insertion section.  To do this, I put text instructions "Click here to Add Image" in the middle of where I want the image, then I added the Image field with "no fill" on top of that text.  This worked great when I inserted a jpeg file because the image covered up my text.  But then I tried inserting a pdf into this space, and my "Click here" text shows right through. (see image).  How do I make it so that when someone inserts the image, the text disappears? Thank you!

 

This topic has been closed for replies.
Correct answer try67

You can change the fill color of the field when it is clicked, like this:

 

event.target.fillColor = color.white;

if (event.target.buttonImportIcon()!=0) event.target.fillColor = color.transparent;

 

The last line of code will change it back to transparent if the user didn't select an image or it failed for some reason.

3 replies

Participant
August 28, 2020

Worked perfectly.  Thanks!

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 28, 2020

You can change the fill color of the field when it is clicked, like this:

 

event.target.fillColor = color.white;

if (event.target.buttonImportIcon()!=0) event.target.fillColor = color.transparent;

 

The last line of code will change it back to transparent if the user didn't select an image or it failed for some reason.

philthedon
Participant
September 9, 2024

What if the background colour is a specific RGB off white, how would you set the fillColour value?

 

try67
Community Expert
Community Expert
September 9, 2024

You can specify a specific RGB value like this:

event.target.fillColor = ["RGB", 0.25, 0.9, 1];

Notice the values are between 0 and 1, not 0 and 255, as in other places.

To convert the latter to the former just divide your values by 255.

Bernd Alheit
Community Expert
Community Expert
August 28, 2020

At the image field use a image with the text "Click here to Add Image" .