0

I'm trying to use TinyMCE 5 with Django CreateView and can't get it to save to the database with the submit button; the form doesn't get submitted, i.e form_valid doesn't get called. The HTML template I'm using works with both CreateView and UpdateView successfully without TinyMCE and the model gets saved to the database.

One of the fields in my model is a TextArea so wanted to try TinyMCE. I downloaded the SDK and have it stored locally. 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. 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

  • Look at your browser dev tools, network tab. What is being submitted over the network? – dirkgroten Oct 20 '19 at 19:59
  • I've just looked and keep seeing this error when the submit button is pressed: An invalid form control with name='description' is not focusable. I'm using bootstrap to render the field, but I don't see this when updating existing data. – alanjohnfrancis Oct 20 '19 at 20:11

1 Answers1

0

I've found a solution thanks to being pointed in the right direction by 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.

Setting either the models field to blank=True, or the form field to required=false solves the problem.