I am working on a django project that utilizes django-ckeditor. I am using HTMX to create a bootstrap modal for displaying my edit form. The form renders correctly, especially after adding the ckeditor.js files at the end of the body in base.html. However, when I open the form in a modal and click save, the form.has_changed() method returns false. It seems like the POST request does not include the changed value for the CKEditor field.
Here is a simplified version of my code:
My model:
class MyModel(models.Model):
name = models.CharField(max_length=50)
description = models.CharField(max_length=150)
comment = RichTextField(blank=True, null=True)
def __str__(self):
return f'{self.name} - {self.description}'
My form:
class MyForm(forms.ModelForm):
class Meta:
model = MyModel
fields = (
'name',
'description',
'comment',
)
My View:
def update_data(request, pk):
model = MyModel.objects.get(id=pk)
form = MyForm(request.POST or None, instance=model)
if request.method == "POST":
if form.is_valid():
print(form.has_changed())
form.save()
return redirect("detail-form", pk=model.id)
Advice needed: When I load the editor after the page has already loaded, the saved changes are not reflected in the POST request. Any suggestions on how to resolve this issue?