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

Allow [up-emit] on buttons #416

Open
triskweline opened this issue Aug 25, 2022 Discussed in #411 · 2 comments
Open

Allow [up-emit] on buttons #416

triskweline opened this issue Aug 25, 2022 Discussed in #411 · 2 comments

Comments

@triskweline
Copy link
Contributor

Discussed in #411

Originally posted by outcassed August 9, 2022
Would it be possible to have unpoly either honor up-emit on <button>s or expose the up-emit click event handler so that it can be easily extended?

--- unpoly.js
+++ unpoly-patch.js
@@ -11642,6 +11642,7 @@
     //    abort = -> up.emit(signal, 'abort')
     //    [abort, signal]
     on('up:click', 'a[up-emit]', executeEmitAttr);
+    on('up:click', 'button[up-emit]', executeEmitAttr);
     on('up:framework:reset', reset);
     return {
         on,
@@ -11654,7 +11655,8 @@
         halt,
         isUnmodified,
         fork,
-        keyModifiers
+        keyModifiers,
+        executeEmitAttr
     };
 })();
 up.on = up.event.on;
```</div>
@triskweline triskweline changed the title up-emit and <buttons> Allow [up-emit] on buttons Aug 25, 2022
@triskweline
Copy link
Contributor Author

This should also work on an input[type=button].

We could just drop the element type from the selector and emit events on anything with an [up-emit] attribute. This is how we already do it for [up-dismiss] and [up-accept].

@alexandergitter
Copy link

Here is another example: I have a table where I would like to be able and emit an event when a row is clicked. Currently I could add an <a> in every <td>, or use <a>s for the rows and set display: table-row on them.
At the moment I use Alpine.js with an x-on:click attribute, that in turn calls an Unpoly function. It would be nice to be able to do this with Unpoly directly.

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

No branches or pull requests

2 participants