Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event handling with formatters #1389

Open
aonghas opened this issue Oct 14, 2024 · 1 comment
Open

Event handling with formatters #1389

aonghas opened this issue Oct 14, 2024 · 1 comment

Comments

@aonghas
Copy link

aonghas commented Oct 14, 2024

Hi there,
Another question more than an issue:
Is there any built-in way to handle events with the formatters? For example, if I wanted to click a chord in the output to change it in the model and update, my current thinking is I'd have to code my own formatter and attach events to the DOM myself rather than use one of the inbuilt formatters (HtmlDivFormatter/HtmlTableFormatter)?

@martijnversluis
Copy link
Owner

Hey @aonghas!

I would say it depends on how you're planning to attach the event handlers.

If you use some library that binds events based on data- attributes, you should probably create a custom formatter based on an inbuilt formatter. If you bind events based on selectors, I'd think that should be possible using the built-in formatters. For example:

function chordClicked(event) {
  // Do something
}

Array.from(document.querySelectorAll('.chord-sheet .chord')).addEventListener('click', chordClicked);

Does this somewhat answer your question?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants