Here is the current documentation:
Anvil Docs | Containers
Here is my code:
rt = RichText()
rt.format = "restricted_html"
rt.content = f"""
<p>
<b>NAME:</b> {email}<br>
<b>PHONE:</b> <a href="tel:{clean_phone}">{phone}</a><br>
{tmp}
</p>
"""
alert(title="Contact Info", buttons=[("Close", True)], content=rt, large=True)
As you can tell the tel:{clean_phone} gets sanitised out.
Can we have “tel” links also allowed alongside http and https?
Thank you
You can achieve the same thing by interpolating an Anvil Link component into the RichHTML Component:
rt = RichText()
rt.format = "restricted_html"
rt.content = f"""
<p>
<b>NAME:</b> {email}<br>
<b>PHONE:</b> {{phone_link}}<br>
{tmp}
</p>
"""
rt.add_component(Link(url=f"tel:{clean_phone}", text=phone), slot="phone_link")
alert(title="Contact Info", buttons=[("Close", True)], content=rt, large=True)
For some reason the Link doesn’t look like it’s a link (e.g. no blue color or underlining), but when you click on it, it does link out like a phone number.
Since the Link component is more versatile and open to any kind of link, I think that the restricted_html RichText is likely to stay restricted in the kinds of URL’s it allows.
Update: The only reason the link didn’t look right was because I was using the Standard Anvil Link in an App with the new M3 library. When I changed it to the M3 Link, it looked correct. So I assume in a non-M3 app you would be perfectly fine styling wise with my code snippet above.
3 Likes
I ended up doing something similar, and I find your m3 test very valuable. I will update my solution to an m3 link now instead of the regular one.
My hope was to make tel: and mailto: and possibly some others available as a legitimate link, but add_component or slot method works too.
Thank you!
1 Like