Replies: 5 comments
-
|
When using FontAwesome js, the original |
Beta Was this translation helpful? Give feedback.
-
|
Yes, indeed, the replacement seems to be the reason. The solution to wrap the element and bind to the wrapper is a good one and I confirm that it works. However, I feel like the events are carried over to the SVG tag, and it's exactly the problem. It would have saved me hours of debbuging if instead of throwing a cryptic error, the click did absolutely nothing. I would have opened DOM, noticed a different tag, and perhaps figured things out. Instead, we get a hard-to-comprehend error and it would be awesome if there's a simple solution to give a meaningful error |
Beta Was this translation helpful? Give feedback.
-
|
The events are not carried over as far as i know. The attributes are so your svg gets to have the alpine directives. Because you are not using a standard variable but a loop iteration variable, when fontawesome replace the item, Alpine sees a new dom item with a directive, tries to evaluate it in the scope of the element and fails. |
Beta Was this translation helpful? Give feedback.
-
|
We may be talking about different meaning of "carried over", so that might confuse me. Here's what I was talking about:
which leads me to believe that it might be possible to detect similar situations But yeah, if it's impossible to fix on the Alpine side, I think it's safe to close the issue. After all, there's a fix to this problem so folks are covered. Or perhaps it deserves a small note in docs. |
Beta Was this translation helpful? Give feedback.
-
|
I think we are talking about the same thing (i was just decribe the root cause from the alpine internal prospective). I believe the onclick handler you see in console is the one generated by
Basically the svg element for alpine is just a new element dinamically inserted in your page at run time, Alpine doesn't know that it's a replacement for the old i tag. Fontawesome technically knows a bit more but i don't think they'll do anything because it's quite tailored to the Alpine use case. I hope it makes sense |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
The title may seem a bit odd, but I think the fault is on
alpineside.Here's what I do:
x-data="{ items: [..., ..., ...] }<template x-for="(id, idx) in items)onclickevent handler and fontawesome styles:<i class="fa fa-trash" @click="console.log(idx)"></i>Uncaught (in promise) ReferenceError: idx is not definedHowever, I expect to see the value of idx in the console.
It seems like font-awesome adds their own event handlers and Alpine tries to wrap them in some way, but fails.
I'm running Firefox 88.0.1, Alpine 2.8.2 and font-awesome 5.15.3
Here's a codepen which illustrates the problem: https://codepen.io/morozzzko/pen/QWpMzmp
Beta Was this translation helpful? Give feedback.
All reactions