Open snackbar via JS/jQuery? #694
sukhcha-in
started this conversation in
4. General
Replies: 1 comment
-
Alpine components are isolated, you can only trigger internal functions using events (well, there's a way to hack into the internal state but it's not documented nor advised since it's an internal api and it could change at any time). <div x-data="snackbar()" @open-snackbar.window="openSnackbar($event.msg, $event.colour)">
...
</div> and from vanilla JS you just trigger the event const event = new CustomEvent("open-snackbar", {
detail: {
msg: '...',
colour : '...'
}
});
window.dispatchEvent(event); There are exemples in old issues and discussions as well. <button x-data @click="$dispatch('open-snackbar')>open</open>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Body with snackbar and it's data:
and here is script tag:
It's working great via
@click
method:But can we open this snackbar programatically via
Js/jQuery
?and I also want to add Delay inside
showSnackbar
function.Beta Was this translation helpful? Give feedback.
All reactions