Using JS package in custom widget
I am trying to create a widget with a chessboard using chessboardjs. I have tried retesting the js and css using
FilamenAsst::register()
and flowed the instructions in the docs but I just get a Failed to open stream: No such file or directory
error. Sorry I know this must be simple to do. Thanks15 Replies
this is a basic example of how to use it
1. install jquery and chessboardjs via npm
2. register assets
3. add to view
Hi, Thank you for your help. I have just tried your solution but got the attached errors. Unfortunately I don't have any experience with Alpin (something I want to rectify) so I don't really understand what is going on here.
can you check the network tab to see the load order of the js files (jquery and chessboardjs)? also try using jquery in the console in the page you put the view code
That's odd I just refreshed the page to watch the network tab and it worked. Thank you. If you have the time would you mind explaining how this is working so I can try and expand on it please
I have also found that the loading of the chessboard is intermittent. Looks like in all cases jquery is loading first. Jquery is working in the console.
i just check my code and it also has the same error, but it rarely occurs, im trying to reproduce it to find out what is happening
I am finding that I am getting the error around 1in5 times Thanks again for your help.
well sorry im not good at explaining things through words (without example code), but basically im using this document https://filamentphp.com/docs/3.x/support/assets#asynchronous-alpinejs-components
you have to make sure that jquery is loaded (accessible via
window.jQuery
) before the chessboardjs script
thats why im using alpine component to init jquery first
I think I am ok with the asset stuff it's that Alpin I'm trying to get my head around. But I thing I am getting there.
Is the above code an example or new code to try?
its an example, you have to follow the document to create an alpine document for it to work
any luck on the error?
im using alpine component instead of the first method to get rid of the error
Sorry I am confused. I thought the first method was an Alpine component.
its not, the first sample code i sent you is just loading the necessary js files, then init the board with it
Right ok.