Reputation: 267
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 :
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.
Upvotes: 0
Views: 1298
Reputation: 35544
This works fine in my case:
<script type="text/javascript" src="ckeditor.js"></script>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Save" OnClick="Button1_Click" />
<script type="text/javascript">
CKEDITOR.replace('<%=TextBox1.ClientID %>');
</script>
For this example to work you have to set ValidateRequest="false"
in the page directive , otherwise you will get a "A potentially dangerous Request.Form value was detected from the client"
error.
If you want to use CKeditor without the PostBack functionality and code begind you can do this:
<script type="text/javascript" src="ckeditor.js"></script>
<textarea rows="9" id="Perfil_Descripcion" name="Perfil_Descripcion"></textarea>
<input id="Button1" type="button" value="Save" onclick="saveText()" />
<script type="text/javascript">
CKEDITOR.replace('Perfil_Descripcion');
function saveText() {
//now you have the data from the editor in javascript
var text = CKEDITOR.instances.Perfil_Descripcion.getData();
alert(text);
}
</script>
From this you can also create an autosave, make a javscript function that is called with a setInterval
and save the text from the editor with CKEDITOR.instances.Perfil_Descripcion.getData()
Upvotes: 1