Django-CKEditor Widget没有动态加载

时间:2021-08-31 06:38:49

I am having problem on loading the second and next ckeditor widget on the front-end form in html. It works well in admin. When I click add more form set dynamically, the widget not come out but showing textarea instead, it just works on the first (initalized) form. I already follow the documentation step by step for basic requirements. I am using Django with django-ckeditor package. Got no javascript errors on the page.

我在html中加载前端表单上的第二个和下一个ckeditor小部件时遇到问题。它在管理员中运作良好。当我单击动态添加更多表单集时,窗口小部件不会出现,而是显示textarea,它只适用于第一个(初始化)表单。我已经逐步了解了基本要求的文档。我正在使用Django与django-ckeditor包。页面上没有javascript错误。

Sorry for not showing any codes before. This is part of the javascript which dynamically adding another form set after button clicked:

很抱歉之前没有显示任何代码。这是javascript的一部分,它在点击按钮后动态添加另一个表单集:

<script src="//cdn.ckeditor.com/4.4.5/standard/ckeditor.js"></script>
<script type="text/javascript" src="ckeditor/ckeditor-init.js"></script>

$('#add_more_work').click(function(){
var form_idx = $('#id_form_set-TOTAL_FORMS').val();
$('#form_set_work').append($('#empty_form_work').html().replace(/__prefix__/g, form_idx));
$('#id_form_set-TOTAL_FORMS').val(parseInt(form_idx) + 1);});

The field which use the ckeditor widget not loading after it added dynamically by this button but instead, it shows plain textarea. Did I miss anything?

使用ckeditor小部件的字段在通过此按钮动态添加后不加载,而是显示简单的textarea。我错过了什么吗?

1 个解决方案

#1


1  

You might want to look at using the formset:added and formset:removed JavaScript signals available from Django 1.9 onwards.

您可能希望查看使用formset:added和formset:从Django 1.9开始删除JavaScript信号。

A simple method (combined from django-content-editor and feincms3 ) might look like this:

一个简单的方法(从django-content-editor和feincms3组合)可能如下所示:

(function($) {
  $(document).on('formset:added', function newForm(event, row) {
    row.find('textarea').each(function() {
      CKEDITOR.replace(this.id);
    });
  });
})(django.jQuery);

I'll leave the handling of formset:removed to the reader.

我将离开处理formset:删除给读者。

#1


1  

You might want to look at using the formset:added and formset:removed JavaScript signals available from Django 1.9 onwards.

您可能希望查看使用formset:added和formset:从Django 1.9开始删除JavaScript信号。

A simple method (combined from django-content-editor and feincms3 ) might look like this:

一个简单的方法(从django-content-editor和feincms3组合)可能如下所示:

(function($) {
  $(document).on('formset:added', function newForm(event, row) {
    row.find('textarea').each(function() {
      CKEDITOR.replace(this.id);
    });
  });
})(django.jQuery);

I'll leave the handling of formset:removed to the reader.

我将离开处理formset:删除给读者。