Custom HTML - Button event binding

I am adding a button in custom HTML. I am not able to see this button in properties neither I am able to add event on it. I am assigning a name to custom button but not able to able to trigger event on this name.

Hi. I’m away from a computer but could you share a clone link so we can take a look?

Click the gear icon in the IDE and follow those instructions.

You may also look at the docs under “custom components”. Sorry just on my phone right now but I can look at things closer later on.

Here is the clone link
https://anvil.works/build#clone:RZNUVPB7EKUALWAT=LLX5P6BWU34HN64J3WXTNN5L

Okay, here’s an app that shows three ways to create a button and handle its click event in Anvil (feel free to read the docs in blue for more info). One approach uses HTML and JS, although I’ve added others that may be simpler depending on your needs.

  • use the standard button component and its click event

  • use Anvil’s custom component feature. Anvil forms are actually components, so if you needed a component with extended and reusable functionality, you could consider this option. Custom components can be found in the toolbox once you click :gear: then “use as component”.
    sc1

    sc2

  • using HTML and JS (JS can call a Python event handler). This option will not show your button as a component on the toolbox AFAIK. Note you do not need to know HTML or JS to use Anvil.

Personally, if you are just looking to manipulate a button in standard ways, just use an Anvil button and avoid the HTML and JS. It is of course certainly possible to use HTML and JS if you prefer.

clone app:
https://anvil.works/build#clone:W5SHZ5BM66ACB2IS=QBYGDT4LCO6ACN7YME3JJ2LK

Does this help to answer your question?

1 Like

Thank you, this article actually helped.

1 Like