"Copy to clipboard" button

That’s just how I did it in one of my projects. I’m sure there are many other ways to lay that out.
As long as the JS function is in scope for the calling form then you should be able to call it ok.

Note my method is not perfect as the JS searches for all elements with that class name then operates on just the first one (element 0). So you need to be careful to not add that role to any other component else it might cause some confusion.

Here’s a version using the JS inside an asset file :

https://anvil.works/ide#clone:IAZHSZY6RUTOUXIQ=VR7BOUTZVNFQ6XWS5ECEB3YY

Things to note here are :

  • cpy() function is now in an asset file “copytext.js”
  • the material theme HTML file (“standard-page.html”) has a “source” tag block loading the asset file
  • you must call_js from the parent file using “get_open_form().call_js()”