Skip to content

Extension events are inconsistent when used with metaCharacter #4084

Description

@scrhartley

The v4 extensions are inconsistent in whether they use htmx.trigger or api.triggerHtmxEvent. The result of this is that when a metaCharacter is used, the user is left to guess what the event name is (and how to use it with hx-on).

In the following example you have:
htmx:prompt and hx-on|htmx:prompt
versus:
htmx|ws|before|connection and hx-on||ws|before|connection (or hx-on|htmx|ws|before|connection)

(These extensions are chosen at random, the problem applies across multiple extensions.)

<!DOCTYPE html>
<html>
  <head>
    <meta name="htmx-config" content='{"metaCharacter":"|"}'>
    
    <script src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0/dist/htmx.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0/dist/ext/hx-prompt.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0/dist/ext/hx-ws.js"></script>
  </head>
  
  <body>
  
    <button

        hx-get="/prompt"
        hx-prompt="Press OK"
        hx-on|htmx:prompt="console.log(event.type); event.preventDefault();"

        hx-ws|connect="/chat"
        hx-on||ws|before|connection="console.log(event.type); event.preventDefault();"

    >
        Prompt
    </button>
  
  </body>
</html>

Aside:
I wish there was a metaCharacter setting so I could do hx-on|htmx:ws:before:connection, since I'd like to be able to use hx-boost|inherited without all my event names becoming hard to read, i.e. htmx|ws|before|connection or htmx|history|cache|before|save.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions