Can images be clickable links in Anvil?

Hi there, I’m attempting to build a website using Anvil, and on my homepage, in the top left of the header, is an image (i.e. my company logo).

I’d like this image to act as the Home button across the various site pages, so when a user is navigating across the site, they can click the image an link back to the Hompage (i.e. Form1).

But I’m not seeing how images can be ‘clickable’ in Anvil. I’m looking at Image Properties and I’m not seeing a Click Event in the Image Container Properties.

Conversely, I see a Link Component can be an Icon (which can be clicked), but can a Link Component also be an Image? That would solve the issue as well in a roundabout way.

Thanks! -Ian

1 Like

Yes, you can make an Image – or any other component – clickable. You do this by putting it inside a Link.

An Anvil Link component inherits from the ColumnPanel component. So you can drag other components inside it, or call self.link_1.add_component(...) on it from code. If you don’t want any text on the link, just set its text property to an empty string.

An Image component inside a Link component will produce a clickable image, which will fire the click event, and/or open the Link’s url property, just like any link.

2 Likes

This is great! I was able to place an image on a Link, and successfully link to an external site using this code:

self.link_home_button.url = "https://google.com"

…but i’m having trouble navigating between forms, i.e. between Form1 and Form2

Forms

I didn’t see how to use the above code to link to a Form, so I created an Event:
Event

with this code:

…and when I run it, I get this error:
error

…and when I define Form2 in Form1,
import

The app runs and I successfully link from Form1 to Form 2. But when I attempt the reverse, setting up a Link Event in Form2 to link to Form1, I get this error:
form 1 not defined

…so I import Form1 into Form2…
import form 1

…and this is the error I get:

Is this a bug or do I need to add a server module to link back and forth between Forms?

Thanks for looking at this and sorry for the long explanation. -Ian