jmrivas86 / django-json-widget

An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields)
MIT License
440 stars 88 forks source link

ReferenceError: Can't find variable: JSONEditor #27

Open thestick613 opened 5 years ago

thestick613 commented 5 years ago

Added the app in INSTALLED_APPS Added the widget in the form If i refresh the admin page, i get

[Error] ReferenceError: Can't find variable: JSONEditor
    (anonymous function) (change:208)
    Global Code (change:211)
[Error] ReferenceError: Can't find variable: JSONEditor
    (anonymous function) (change:231)
    Global Code (change:234)
        var editor = new JSONEditor(container, options);
        var json = {"a": "b"};
        editor.set(json);
jsmedmar commented 5 years ago

Same problem here... Googling Uncaught ReferenceError: JSONEditor is not defined throws a bunch of github issues. Seems to be a problem with the underlying tool being used

jsmedmar commented 5 years ago

As for now, I managed to fix it with this:

from django_json_widget.widgets import JSONEditorWidget

class CustomJSONEditorWidget(JSONEditorWidget):
    # hardcode media until this issue gets resolved
    # https://github.com/jmrivas86/django-json-widget/issues/27
    class Media:
        extend = False
        css = {
            "all": (
                "https://cdnjs.cloudflare.com/ajax/libs/"
                "jsoneditor/7.0.4/jsoneditor.min.css",
                "https://cdnjs.cloudflare.com/ajax/libs/"
                "jsoneditor/7.0.4/img/jsoneditor-icons.svg",
            )
        }
        js = (  # pylint: disable=invalid-name
            "https://cdnjs.cloudflare.com/ajax/libs/"
            "jsoneditor/7.0.4/jsoneditor.min.js",
        )
fedorbeets commented 4 years ago

Using django-json-widget==1.0.1 Django==3.0.3 and Python 3.8.2

I still get the issue ReferenceError: JSONEditor is not defined. The above solution of creating a custom widget did not work for me.

I ofcourse added the app in INSTALLED_APPS and the widget to the form ala widgets = {'configuration': CustomJSONEditorWidget}

I had to add:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/5.13.2/jsoneditor.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/5.13.2/jsoneditor.min.css" type="text/css" media="all" rel="stylesheet">

To the top of the form.

Adding the django-json-widget to the admin interface does work without any adjustments. Does anyone have a fix that lets you use the normally included jsoneditor files in forms?

daved-lacite commented 4 years ago

I did a collectstatic to get the files in the static folder of the project, if you are running the server from apache, or from anything else than a runserver, the files need to be in the static folder in order to be served.

python manage.py collectstatic

fedorbeets commented 4 years ago

Once I did a collectstatic the issue didn't fix itself, but I included a local copy of the files that were collected in the page iwth the JSONEditor, and this solves the problem for now.

ablakey commented 4 years ago

All I had to do was a collectstatic given I'm using storages to put static assets in AWS. <-- Just a breadcrumb in case someone else comes looking for insight.

berkcoker commented 3 years ago

Make sure dist is not in your .gitignore since this library adds its static files into /static/dist