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

How to associate event handler callback #30

Open
egil opened this issue May 2, 2024 · 0 comments
Open

How to associate event handler callback #30

egil opened this issue May 2, 2024 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@egil
Copy link
Owner

egil commented May 2, 2024

When a component has markup that includes event handlers, Htmxor needs to be able unambiguously identify which event handler to invoke., e.g.:

These two are unambiguous because they reference the 
same event handler method even though their hx-get attribute 
has the same value.
<div hx-get="/" @hxget=@HandleGet />
<div hx-get="/" @hxget=@HandleGet />

These two are ambiguous because the event handlers (lambda) 
are distinct and they share the same hx-get value.
Will cause Htmxor to throw.
<div hx-get="/page" @hxget=(() => {}) />
<div hx-get="/page" @hxget=(() => {}) />

These two are unambiguous because they reference 
distinct event handlers and their hx-get attribute are different.
<div hx-get="/page2" @hxget=(() => {}) />
<div hx-get="/page3" @hxget=(() => {}) />

@code {
  private void HandleGet(HtmxEventArgs args) { }
}

This works as illustrated above, i.e. based on the hx-ACTION's attribute value. However, this could be extended to include other unique attributes on the element the handler is attached to, e.g.:

  • ID of the element. These are expected to be unique.
  • Value passed to @key Blazor attribute. This is expected to be unique.
  • A fallback, e.g. custom hx-ACTION-key attribute.

This avoids users having to custom query parameter on their action URLs.

@egil egil added enhancement New feature or request help wanted Extra attention is needed labels May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant