Cannot read properties of undefined (reading 'nestable')
Hi, I'm facing the following issue:
Alpine Expression Error: Cannot read properties of undefined (reading 'nestable')
Expression: "function () {
let nestedTree = $('#filament_tree_container_BxCAKyCkwLPukL2rHBKg').nestable
.
.
.
To be exact, it's happening in components/tree/index.php file. Looks like its not able to find the JQuery here. $('#{{ $containerKey }}') returns undefined while document.getElementById('{{ $containerKey }}') returns object.
The temporary solution we adopted is loading Jquery and package js at the end of file. For example, we created the view:
<script src="https://code.jquery.com/jquery-3.6.1.slim.min.js"
integrity="sha256-w8CvhFs7iHNVUtnSP0YKEg00p9Ih13rlL9zGqvLdePA="
crossorigin="anonymous"></script>
<script src="{{asset('js/solution-forest/filament-tree/filament-tree-min.js')}}"></script>
And loaded it at the end of body using Filament hook.
->renderHook(
'panels::body.end',
fn (): View => view('filament/resources/custom-body-end-js-cmspanel'),
)
I attempted a PR that registers JS assets at the body end. https://github.com/solutionforest/filament-tree/pull/38
Running in to this issue aswell
Same issue, Sometimes due to unstable network, will encounter the problem that jquery-3.6.0.min.js cannot be loaded.
Below is my solution:
- Add new middleware named
ReplaceAssetsand replace<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>string. - Register the new middleware.
- Download
jquery-3.6.0.min.jsand saved topublic/js/solution-forest/filament-tree/jquery.min.js. - Loaded it at the start of body using Filament hook.
Below is the demo code:
- Add new middleware
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class ReplaceAssets
{
/**
* Handle an incoming request.
*
* @param Closure(Request): (Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$response = $next($request);
$search = '<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>';
$replace = '';
$response->setContent(Str::replace($search, $replace, $response->getContent()));
return $response;
}
}
- Register middleware
<?php
namespace App\Providers\Filament;
use App\Http\Middleware\ReplaceAssets;
class AdminPanelServiceProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
// ...
->middleware([
// ...
DispatchServingFilamentEvent::class,
ReplaceAssets::class, // Add this line
]);
}
}
- Download
jquery-3.6.0.min.jstopublic/js/solution-forest/filament-tree/jquery.min.js - Loaded it at the start of body using Filament hook
<?php
namespace App\Providers\Filament;
use function asset;
class AdminPanelServiceProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
// ...
->renderHook(
'panels::body.start',
fn (): string => sprintf("<script src='%s'></script>", asset('js/solution-forest/filament-tree/jquery.min.js')),
);
}
}
Hello, any update on this issue?
See #51