1

我有内联表单集。我使用django-wysiwyg在某些字段上设置 WYSIWYG 编辑器。
加载页面后,一切正常。我用来{% wysiwyg_editor form.worktime.auto_id %}在字段上设置编辑器。
但是当我动态地向 inlineformset 添加一个表单时,没有编辑器出现。
这是表格:

class CommentForm(forms.ModelForm):

    class Meta:
        model = Comment
        fields = '__all__'

InstitutionDoctorsFromSet = inlineformset_factory(Institution, Doctor, fields='__all__', extra=1)

和模板:

  <form class="the_form" enctype="multipart/form-data" method="post">
        {% csrf_token %}
        {{ form.as_p }}
        {% wysiwyg_editor "id_services" %}
        <fieldset>
            <legend>Doctors:</legend>
            {{ doctor_form.management_form }}
            {% for form in doctor_form %}
                {{ form.id }}
                <div class="inline {{ doctor_form.prefix }}">
                    {{ form.as_p }}
                    {% wysiwyg_editor form.worktime.auto_id  %}
                </div>
            {% endfor %}
        </fieldset>
        <input class="btn btn-default" type="submit" name="submit" value="Update"/>
    </form>

如果我在浏览器控制台中运行以下 js 代码 - 编辑器会出现: django_wysiwyg.enable('ckeditor', 'id_doctor_set-3-regime')id_doctor_set-3-regime字段的 id 在哪里,我需要一个编辑器。但是可以有很多领域,所以我需要更灵活的解决方案。
我想我需要在加载表单集时实现一些东西,或者在添加子表单时捕获一个事件,但我不知道如何。

4

1 回答 1

1

更改:{% wysiwyg_editor "id_services" %} on:{% wysiwyg_editor "id_doctors" %}

于 2015-08-27T13:44:33.747 回答