I try to save my form with CKEditor and add autosave function mean all input will autosave:
<script>
CKEDITOR.replace('Perfil_Descripcion');
</script>
<script>
$('document').ready(function () {
$('#preview').hide(); //Default setting
for (instance in CKEDITOR.instances) {
CKEDITOR.instances[instance].updateElement(); //fix texrarea update value
CKEDITOR.instances[instance].on('key', function () { //save, here comes the error
$("#btnUpdatePerfil").trigger('click');
});
}
});
//Save in db
function CKUpdate() {
for (instance in CKEDITOR.instances) {
CKEDITOR.instances[instance].updateElement();
$('#generalform').ajaxForm({
target: '#preview',
success: function () {
$('#preview').show('slow').delay(800).hide('slow');
}
});
}
}
<form id="generalform" method="get" action="?">
<h3 class="page-header">Descripcion sobre tu persona</h3>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<!--<textarea id="editor" class="form-control"></textarea>-->
<textarea class="form-control" rows="9" id="Perfil_Descripcion" name="Perfil_Descripcion"></textarea>
<span id="preview"></span>
</div><!-- /.form-group -->
</div>
</div>
</form>
My problem is :
- This autosave CKupdate() (refer line -> comment //auto save ) trigger when i put some text, but have bugs, because save it sometimes. Im not sure how to fix the bug.
- After user press save, save function will trigger everytime user insert any string inside textarea and after few second my browser will hang. I think this on('key', not function well or maybe need to change to someting else, like a click function, but also have bugs and sometimes save it.
what im trying to do actually is create textarea with CKEditor then save value into db and create a function to display in the textarea for edit the content.
Another problem is that I have to quickly press the save button.