HTML a href & server callable

I have a form whose content is HTML with link created programatically like so:
Code Sample:

html_template = HtmlTemplate()
html_template.html = '<a href="server callable...">some link</a>'
    
get_open_form().content_panel.clear()
get_open_form().content_panel.add_component(html_template)

I would like that after clicking the link server callable function is called, and its result is used as a new html.
How can I do it?

It’s almost certainly easier to just use the built-in anvil link component that has a click event to hook into:

1 Like

To me, this sounds like HTMX-style programming. That bypasses much of what Anvil has to offer, but if it’s familiar to you, that may be more important.

Not my area of expertise, but since you’re working at the HTML/JavaScript level, I’d start here, to get familiar with the provided tools and techniques: Using JavaScript. You can build up from there.

Give the href an anvil-name or id, then use the html custom component logic to add a click event. Just have a play around. Failing that give the link an ID and use the JS bridge.

You may have good reasons for creating links programmatically using HTML, but in Anvil it’s usually much easier to add a Link component and setup its events programmatically and work in Python only, rather than working like those poor people in the outer non-Anvil world with HTML and Javascript.