I have inline formset. And I use django-wysiwyg to set WYSIWYG editor on some fields.
When page is loaded, everything works perfectly. I use {% wysiwyg_editor form.worktime.auto_id %}
to set editor on field.
But when I dynamicaly add one more form to inlineformset, there is no editor showing up.
Here is form:
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = '__all__'
InstitutionDoctorsFromSet = inlineformset_factory(Institution, Doctor, fields='__all__', extra=1)
And template:
<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>
If I run following js code in browser console - the editor appears:
django_wysiwyg.enable('ckeditor', 'id_doctor_set-3-regime')
, where id_doctor_set-3-regime
is id of a field, that I need to have an editor. But there can be many fields, so I need more flexible solution.
I think I need to implement something when formset is loaded, or catch an event when subform is added, but I don't know how.
change: {% wysiwyg_editor "id_services" %} on: {% wysiwyg_editor "id_doctors" %}