简体   繁体   English

Django CreateView 不适用于 TinyMCE 5

[英]Django CreateView not working with TinyMCE 5

I'm trying to use TinyMCE 5 with Django CreateView and can't get it to save to the database with the submit button;我正在尝试将 TinyMCE 5 与 Django CreateView 一起使用,但无法通过提交按钮将其保存到数据库中; the form doesn't get submitted, ie form_valid doesn't get called.表单没有被提交,即 form_valid 没有被调用。 The HTML template I'm using works with both CreateView and UpdateView successfully without TinyMCE and the model gets saved to the database.我正在使用的 HTML 模板在没有 TinyMCE 的情况下成功地与 CreateView 和 UpdateView 一起使用,并且 model 被保存到数据库中。

One of the fields in my model is a TextArea so wanted to try TinyMCE.我的 model 中的一个字段是 TextArea,所以想尝试 TinyMCE。 I downloaded the SDK and have it stored locally.我下载了 SDK 并将其存储在本地。 I then placed the following in the head tags as per the documentation:然后我根据文档将以下内容放在头标签中:

<script src="{% static 'tinymce/js/tinymce/tinymce.min.js' %}"></script>
<script type="text/javascript">
    tinymce.init({
        selector: '#id_description',
    });
</script>

With this in place, I can see and use the TinyMCE editor when both Creating a new model and updating an existing one, but I can no longer save new model data to the database.有了这个,我可以在创建新的 model 和更新现有的 model 时看到并使用 TinyMCE 编辑器,但我不能再将新的 model 数据保存到数据库中。 Funny thing is though, I can still update and save existing data.有趣的是,我仍然可以更新和保存现有数据。

Since I can update existing data, but not new data, I think this is probably a bug.由于我可以更新现有数据,但不能更新新数据,我认为这可能是一个错误。 Can anyone confirm please.谁能确认一下。

Thanks谢谢

I've found a solution thanks to being pointed in the right direction by dirkgroten.由于 dirkgroten 指出了正确的方向,我找到了解决方案。 The error I saw in my browser's dev tool - "An invalid form control with name='description' is not focusable", lead me to the following article: "Invalid form control" only in Google Chrome .我在浏览器的开发工具中看到的错误 - “名称='description' 的无效表单控件不可聚焦”,引导我阅读以下文章: “仅在 Google Chrome 中的无效表单控件”

Setting either the models field to blank=True, or the form field to required=false solves the problem.将模型字段设置为空白=True,或将表单字段设置为 required=false 可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM