Laracasts Alpine code in an action
Im following a guide on laracasts and im at a point for it has a form component, and has attributes for: x-data, x-on:submit.prevent.
I am wondering if I can use a custom action to call the alpinejs function from my app.js file, rather than creating a new blade file etc
Bit lost trying to find this in the docs?
24 Replies
Anyone have any idea?
please provide mor info what you are trying to do..
So I have a function in my app.js called 'registerPasskeys' that has some js logic.
I want to have an action that fires off that js function
if you register your js file, you can call this using
->alpineClickHandler('registerPasskeys')
Ill give that a go when im back in the office tomorrow, thank you
Morning, I've just managed to have a test of this, im getting 'registerPasskey' is not defined, and im not sure the correct syntax.
The above is my alpinejs code.
I tried registerPasskey, registerPasskey.register and just register, none of which work
It looks like its searching the livewire.js file but I have it defined in my app.js file.
So moved code into a custom.js file,
Registered in service provider:
When I refresh browser, I initially get this:
And when I click my button, its still searching in the livewire.js file instead of my custom.js
Are you using
import axios
in your custom JS?Yeah
Custom.js
I see the "alpine initializing" console log, so the file is being read.
Just when I click the button I get this
Try to import via cdn instead of
Does that mean like this:
As thats spat out a whole lot of errors in dev tools,
If I move the logic outside of the Alpine.data function, it works. So its something to do with the Alpine.data not registering it as a component or its registered but the alpineClickHandler cant detect it.
sorry for the delay.. where are you using this action?
register
axios
and simplewebauthn
via cdn in your appserviceprovider
Try this
don't forget to run php artisan filament:assets
to publish the assetsSorry, I got caught in a meeting.
So the action is in a relationmanager, in the headerActions array.
I've added the code you linked above and got the following errors. The first 2 are just because Ill have to add the urls to the cors part of my docker container.
I got a cannot use import statement outside a module error, then that the registerPasskey is not defined.
This again being my code:
remove imports and register via cdn in your provider