I am using ckeditor with the jQuery adapter in an ajax scenario. The ckeditor is bound to a textarea element using jQuery.
The App:
I am designing an eLearning app for a client. Each course has many steps, drawn from a database table.
The UI of the app is just a form with Previous and Next buttons to navigate through the course.
The issue is with the admin facility, where Tutors can create and update the steps in each course.
Again, the admin facility is just a form with previous and next buttons. However, there is a field called StepText that I want to have html rather than plain text. Hence the requirement for a Rich Text Editor.
The scrolling from step to step is down with Ajax calls, that go off to the controller, get the data for the next (or previous) step, and inject it into the page. The ajax calls return html, created from a partial view.
The Problem:
The textarea is in this partial view. The CKEditor binds correctly the first time the page is loaded, but not for any subsequent ajax responses.
The result is that the ckEditor does not appear with all its goodness and I just get the unappealing nakedness of the textarea.
Any ideas why this is happening?
SETUP (Shown for Refrence) (Edited):
The following scripts are used:
<script type="text/javascript" src="@Url.Content("~/ckeditor/ckeditor.js")"></script>
<script type="text/javascript" src="@Url.Content("~/ckeditor/adapters/jquery.js")"></script>
This allows me to use ckEditor with jQuery as follows:
$(document).ready(function () {
$('#StepText').ckeditor(function () { }, { toolbar: 'Basic' });
});
The text area is in a partial .cshtml file, within a div that acts as the target for the ajax call:
Edited!! to show how the ajax call is made !!
<div id="ajaxEditor">
@using (Ajax.BeginForm(MVC.Admin.StepEditor.Edit(), new AjaxOptions { UpdateTargetId = "ajaxEditor", HttpMethod = "POST" },
new { @name = "EditStepForm", @id = "EditStepForm" }))
{
<div class="editor-label">
@Html.LabelFor(model => model.StepText)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.StepText, 20, 68, null)
@Html.ValidationMessageFor(model => model.StepText)
</div>
}
</div>
Response to Chris Marisic:
I tried rebinding the ckeditor in the OnSuccess of the ajax call, but when debugging the jQuery in Chrome, I get the following error:
Uncaught [CKEDITOR.editor] The instance "myTextArea" already exists.
Which is what you would expect: the control name is still the same and there has not been a full page refresh.