Any easy way to automatically wire an extra event to all buttons?

Hey there,

I was wondering if there was any way to add a global event to all buttons somehow? (Or all elements actually)

An example use-case would be for logging. Any time any button is pressed, send an event to Console.Writeline(button => button.Title)

I'm trying to make things easier for my QA engineer... so the idea is that every time she clicks something, it'll just write await {pageName}.ClickButtonAsync({buttonTitle}); to a log file. Then at the end of her manual testing session she can copypaste everything to BUnit or Selenium

I'm not that great with raw css or javascript. If this is possible with vanilla javascript and I can just wire events to all .rz-button items that's fine too

I know libraries like Google Analytics do something like this, and wire themself to click events to send them to google, so I was thinking there must be some way to generically do this

Otherwise I'm thinking I'll have to create all of my own components, like GlobalEventButton : RadzenButton and inject something in the click event...

Was hoping someone would have some advice on how to best do this, thanks

You can do that with both JS and by overriding the RadzenButton. However if you chose the latter you have to replace all occurrences of RadzenButton which would require adding a lot of files to Radzen's code generation ignore list. The JavaScript solution can be done with event capturing and using Blazor interop.