I am new to using the Froala editor and I am currently working on a feature where I need to save text in the textarea of the editor when the user clicks outside of it using Ajax. The ID of the content editor is #id_content
.
Here is a snippet of my form in Django:
<form method="POST" id="froala_form" class="PageForm _inputHolder">
{% csrf_token %}
<div class="_alignRight posR _saveBTNOut">
<button type="submit" class="_btn btnPrimery">Save as Draft</button>
</div>
</form>
Despite my efforts, I have not been able to come up with a suitable logic for this task.
function loadDoc(){
var xhttp=new XMLHttpRequest();
xhttp.onreadystatechange=function{
if(this.readyState==4 && this.status==200){
var x = document.getElementById("id_content");
x.addEventListener("click", ajaxsavefunc);
}
};
xhttp.open("GET",'url', true);
xhttp.send();
}
function ajaxsavefunc(xhttp) {
document.getElementById("froala_form").innerHTML = editor.html.get()
}