1

I'm using CkEditor for Django and I have a form with 3 fields, a product code, a subject and a body. The first two fields are normal fields and the body field is a CKEditor field that is being rendered on the template from forms.py. In order to do an ajax call on this data, I need to use Jquery to get the CkEditor content. How to do this? This is my code so far.

My template:

form action="." method="post">    
    {{form2.as_p}}
    {% csrf_token %}
    <br><button name="form_submit"  id="email_submit" type="submit" class="btn btn-primary" value="send_email">Submit</button>
</form>

My forms:

class CustomersWhoBoughtForm(forms.Form):
    product_code = forms.CharField(required=True,  max_length=1000, label='Product Code')
    subject = forms.CharField(required=True, max_length=1000,  label='Email Subject')
    body = forms.CharField(widget=CKEditorUploadingWidget(config_name='default')) #trying to get value of this field for Ajax Call

I tried this:

var product_id= $('#id_product_code').val();   //This works
var subject = $('#id_subject').val();          //Also works
var body = $('#id_body').val();                //Does not work, neither does ck_id_body

2 Answers 2

4

This question nothing to do with django or python. It is pure about how to get the content from CkEditor and if you search there will be tons of answers on this topic.

Here is how you can get the content of the editor:

var value = CKEDITOR.instances['id_body'].getData()
Sign up to request clarification or add additional context in comments.

Comments

1

I also had the same issue with django-ckeditor,What I tried is

<script type="text/javascript">
     for (var instance in CKEDITOR.instances)
            CKEDITOR.instances[instance].updateElement();


var temp = CKEDITOR.instances[instance].getData();

it works fine,the variable named temp holds the value.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.