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

Empty field value when loaded by HTMX #446

Open
H4rryK4ne opened this issue Aug 18, 2023 · 1 comment
Open

Empty field value when loaded by HTMX #446

H4rryK4ne opened this issue Aug 18, 2023 · 1 comment

Comments

@H4rryK4ne
Copy link

I don't get the content of the HTMLField if I use this in a dynamically loaded view with HTMX.

StackOverflow seems to have already some questions regarding this issue:

Unfortunately, my JavaScript skills are not yet developed enough, to apply any of the proposed solutions (This is also the reason, why I was very happy to find HTMX, which solves a lot of my issue, where JS would be required)

#416 mentions a similar issue, but with bootstrap

@sdolemelipone
Copy link

The fix to one of the questions you linked to will solve your problem: https://stackoverflow.com/a/24284657/1785448.

django-tinymce knows to automatically evaluate javascript functions if they are defined in python strings for specific configuration options, like "setup". So in your settings.py:

# All of the below are the defaults from django-tinymce's documentation 
TINYMCE_DEFAULT_CONFIG = {
    "theme": "silver",
    "height": 500,
    "menubar": False,
    "plugins": "advlist,autolink,lists,link,image,charmap,print,preview,anchor,"
    "searchreplace,visualblocks,code,fullscreen,insertdatetime,media,table,paste,"
    "code,help,wordcount",
    "toolbar": "undo redo | formatselect | "
    "bold italic backcolor | alignleft aligncenter "
    "alignright alignjustify | bullist numlist outdent indent | "
    "removeformat | help",
    # Add a setup function to apply a fix for HTMX:
    "setup": "function (editor) {editor.on('change', function () {tinymce.triggerSave();});}",
}

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

2 participants