Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.04k stars 885 forks source link

[Bug] nestedSortable is not a function #5436

Closed gaborfarkas0211 closed 6 months ago

gaborfarkas0211 commented 6 months ago

Bug report

What I did

Use ReorderOperation trait, and set up the required fields ('label' and 'max_level'). Opening the /reorder route from the list operation to reorder tree elements with drag and drop.

What I expected to happen

Could reorder the tree elements with drag and drop.

What happened

Console error on page load: Uncaught TypeError: $(...).nestedSortable is not a function at HTMLDocument. (reorder:656:28)

What I've already tried to fix it

I've made several attempts with the basset to import the lib, but none of the versions succeeded. In the end, I copied the content of the file "jquery.mjs.nestedSortable2.js" from "vendor/backpack/crud/src/resources/assets/libs" and pasted it between the script tags in the "after_scripts" section of the "reorder.blade.php" file, and that's how the ordering worked.

Is it a bug in the latest version of Backpack?

After I run composer update backpack/crud the bug... is it still there?

Yes

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

welcome[bot] commented 6 months ago

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

-- Justin Case The Backpack Robot

jcastroa87 commented 6 months ago

Hello @gaborfarkas0211 did you try with a clean installation?

I tested with our demo :

use \Backpack\CRUD\app\Http\Controllers\Operations\ReorderOperation;

public function setup()
{
    CRUD::setModel(\App\Models\PetShop\Owner::class);
    CRUD::setRoute(config('backpack.base.route_prefix').'/pet-shop/owner');
    CRUD::setEntityNameStrings('owner', 'owners');

    $this->crud->enableReorder('name', 2);
}

And is working as expected (no console log)

Screenshot 2024-02-01 at 14 54 09

Here is tested versions:

### PHP VERSION:
PHP 8.2.11 (cli) (built: Oct  6 2023 09:46:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.11, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.11, Copyright (c), by Zend Technologies

### LARAVEL VERSION:
10.31.0.0

### BACKPACK PACKAGE VERSIONS:
backpack/activity-log: 2.0.0
backpack/backupmanager: v5.0.0
backpack/basset: 1.2.1
backpack/crud: 6.3.0
backpack/demo: dev-main
backpack/editable-columns: 3.0.2
backpack/filemanager: 3.0.5
backpack/generators: v4.0.2
backpack/language-switcher: 1.0.1
backpack/logmanager: v5.0.1
backpack/medialibrary-uploaders: 1.0.1
backpack/menucrud: v4.0.1
backpack/newscrud: v5.0.0
backpack/pagemanager: 3.2.0
backpack/permissionmanager: 7.1.1
backpack/pro: 2.0.18
backpack/revise-operation: 2.0.0
backpack/settings: 3.1.0
backpack/theme-coreuiv2: 1.2.2
backpack/theme-coreuiv4: 1.1.1
backpack/theme-tabler: 1.1.1

If you have a problem with basset, did you try to clean cache:

php artisan basset:clear

Or follow the instructions here

Cheers

gaborfarkas0211 commented 6 months ago

Thank you for your help, basset did not work properly because the APP_URL was not set correctly - php artisan basset:check command helped from the documentation.

jcastroa87 commented 6 months ago

Great news that you solved it.

I will close the issue, but please feel free to reopen or create new one if it needed.

Cheers