0

I've been playing with Django Crispy Forms the last couple of days...It's working...Kinda...But now I'm running into a problem with the TinyMCE editor. I'm running django-tinymce 3.3.0. The TinyMCE field displays via the normal template, but when I run an ajax call to return the form via the render crispy form, it won't display. All of the other fields display via the django crispy forms view...but not the TinyMCE. I've been tracking two different errors in the console.

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/....

I found an article that says to set...

async: False...

On my AJAX call but it didn't help..

Uncaught TypeError: n.ui.isDisabled is not a function....

I've read a few articles that says this might be a plugin conflict...but can't find any issues here.

I'm running an AJAX call...

 $.ajax({
     method: 'post',
     headers: { "X-CSRFToken": token },
     url: "{% url 'Procedures:create_procedure' %}",
     processData: false,
     contentType: false,
     cache: false,
     data: formData,
     enctype: 'multipart/form-data',
     success: function (response) {
            if (response.succes == true) {
                  $('#id_username').alert("Hello");
            }
            else {
                $("#forms").replaceWith(response['form_html']);
             }

        }, 
  });

});

My FORMS.py....

class Meta:
    model = NewProcedure
    exclude = [ 'created_by',]

    procedure = forms.CharField(widget=TinyMCE(attrs={'cols': 50, 'rows': 30}))

def __init__(self, user, *args, **kwargs):
    User = get_user_model()
    super(CreateProcedureForm, self).__init__(*args, **kwargs)
    self.helper = FormHelper()
    self.helper.form_tag = False
    self.helper.layout = Layout(
        Div(
            HTML("<h1 class='title62'>Create New Procedure</h1>"),
            Field('procedure', forms.CharField(widget=TinyMCE(attrs={'cols': 50, 'rows': 30}))),
            Submit('submit', 'Submit'),
            )
        )

I've also tried to add {{ form.media }} to my template but that doesn't help either. I can finally get the crispy forms to show the fields I'm trying to display...except for the TinyMCE field.

I've also tried...

{{ form.procedure|as_crispy_field }}

In the form...No dice.

I'm trying to render the fields individually...but just for fun I changed the template and tried both...

{% crispy form %}
{{ form|crispy }}

And these both render the form.....everything except for the TinyMCE field...the LABEL renders...but the field itself is not displaying on the form.

Steve Smith
  • 1,019
  • 3
  • 16
  • 38
  • Could you have conflicting jQuery instances running? – andyw Oct 26 '21 at 14:30
  • @andyw Thanks for the thought. Will play with my libraries and see if this is maybe the case. – Steve Smith Oct 26 '21 at 14:31
  • Remove the line starting "Field('procedure', forms.CharField..." and try just 'procedure' – andyw Oct 26 '21 at 14:31
  • de-indent "procedure = forms.CharField(widget=TinyMCE(attrs={'cols': 50, 'rows': 30}))" – andyw Oct 26 '21 at 14:34
  • @andyw Thanks for the suggestions. Doesn't seem to work. I did in fact remove one of my jquery libraries but then nothing rendered. I'll keep exploring in that area. The other suggestions did not work. Thanks for taking the time to try to help me. – Steve Smith Oct 26 '21 at 14:45
  • We use the package in our signup page here. Might be worth comparing eg jquery versions https://testxr.org/accounts/signup/ – andyw Oct 26 '21 at 15:12
  • @andyw Thanks. I poked around but haven't found anything as of yet. Again appreciate the assist. Thank you. – Steve Smith Oct 26 '21 at 21:26

0 Answers0