ziming/json-field-for-backpack

Uncaught ReferenceError: JSONEditor is not defined

Astriel opened this issue · 3 comments

Hello there !

I've just installed the plugin on a Laravel Backpack V6 project.

`### PHP VERSION:
PHP 8.1.2 (cli) (built: Jan 19 2022 10:18:23) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies

LARAVEL VERSION:

10.16.1.0

BACKPACK PACKAGE VERSIONS:

backpack/basset: 1.0.2
backpack/crud: 6.1.1
backpack/devtools: 2.0.3
backpack/generators: v4.0.2
backpack/permissionmanager: 7.0.0
backpack/pro: 2.0.10
backpack/theme-coreuiv4: 1.0.5`

I'm trying to add the json field as a subfield on the create crud :
CRUD::field([ 'name' => 'test', 'type' => "relationship", 'tab' => 'Test', 'label' => 'Test', 'subfields' => [ [ 'name' => 'test_relationship_id', 'label' => 'Json textarea', 'type' => 'json', 'view_namespace' => 'json-field-for-backpack::fields', 'modes' => ['form', 'tree', 'code'], 'tab' => 'Test', 'wrapper' => [ 'class' => 'form-group col-md-6', ], ], ], ]);

Unfortunatly, when I'm going on the create page I've got the following message :
create:1050 Uncaught ReferenceError: JSONEditor is not defined at create:1050:57

Any idea on how to solve the problem ? I tried to publish vendor files, but sounds like I can't publish anything related to this package.

Sounds like this code is not executed because the following dependencies are not loaded.

@if ($crud->checkIfFieldIsFirstOfItsType($field, $fields))
    @push('crud_fields_styles')
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/9.10.2/jsoneditor.min.css" />
    @endpush

    @push('crud_fields_scripts')
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/9.10.2/jsoneditor.min.js"></script>
        <script>
            let container, jsonString, options, editor;
        </script>
    @endpush
@endif
ziming commented

hmm I'm using it in production on a backpack v6 admin site and it is fine

I see ur using it on a backpack subfield. I have not used a backpack subfield before

when my schedule is more free I will try to look into a fix for this field on subfield if possible. but it might be weeks away

but in the mean time if ur willing to try PR a fix, feel free :)

thanks for bringing this to my attention

ziming commented

Hi do you still have the problem? and if u still have could you provide some sample data that cause the error as well as nicely formatted code example to try reproduce it? Thank you