Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File input doesn't show up #244

Closed
WollenMoth opened this issue Feb 16, 2022 · 4 comments
Closed

File input doesn't show up #244

WollenMoth opened this issue Feb 16, 2022 · 4 comments

Comments

@WollenMoth
Copy link

I'm trying to use django-s3direct on the admin page.
Followed the steps to use the example, but inputs doesn't appear in admin form.

image

I'm using Python 3.10 and Django 4.0.2

I would like to use django-s3direct in other proyect with the same versions, so I cannot downgrade.

@WollenMoth
Copy link
Author

WollenMoth commented Feb 16, 2022

Form page doesn't work either.

image

And I'm getting this error on the browser console.

image

@jwqian99
Copy link

I encountered the same error using the latest (2.0.0) release, downgraded to 1.1.8 worked.

python 3.10, djanog 3.25, djang-s3direct 1.1.8

@byteofwood
Copy link

I think I discovered what is causing this issue. s3direct's script tag is inserted in the head. This means that this part of s3direct's script (the last ~150 chars of /static/s3direct/dist/index.js, prettified) is run before the page is fully loaded.

...
new MutationObserver((function(t) {
    [].forEach.call(document.querySelectorAll('.s3direct'), A)
}))
    .observe(document.body, {
        childList: !0,
        subtree: !0
    })

I believe document.body is null at the time it is run which causes the "parameter 1 is not of type 'Node'." I bodged this by putting the script at the end of the body by adding to the admin template. Info in this SO answer.

My /templates/admin/base_site.html file:

{% extends 'admin/base_site.html' %}
{% load static %}

{% block footer %}
    <div id="footer"></div>
    <script src="/static/s3direct/dist/index.js"></script>
{% endblock %}

This fixes the input not showing up problem for me. Hopefully there is a better way to solve this, perhaps jquery's .ready(), javascript's window.onload, or by somehow telling django to put the script at the end of the body (I'm not sure if this is possible using the Media class), or maybe even putting the script in the widget's template.

@bradleyg
Copy link
Owner

Should be fixed in the latest release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants