This is a migrated thread and some comments may be shown as answers.

Render the Javascript only

2 Answers 35 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 07 Jul 2014, 04:43 PM
Hi,

I am switching between the kendo editor and plain text using jquery. I'm destroying the kendoEditor and then removing it from the DOM in such a way that the textarea is left behind. Then if I need to switch back to the editor I call $("#Test").kendoEditor() again. This works pretty well so far.

My first question is: Is there a simpler way of doing this?

My second question is: I'd like to write out the Javascript that converts the textarea to an editor only once. Is there a way to tell the Html helper to render just the javascript so I can put the output into a function?

For example. @Html.Kendo().Editor().Name("Test").Encode(false) will write out both the textarea and the javascript. Can I get it to write just the javascript?

Many thanks,
Bill

2 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 09 Jul 2014, 11:35 AM
Hello Bill,

An alternative approach to destroying and recreating the Editor is to use separate textarea and Editor widget, and toggle their visibility. This is not necessary simpler or better - it depends on your scenario and implementation.

The Kendo UI server wrappers are designed to render both the required HTML markup and Javascript initialization statement and this cannot be changed. Theoretically, you have an option to hack the widget like this:

Capture the widget HTML output and defer the script output, so that they are not rendered immediately and automatically. Then render the HTML and/or script outputs separately where you want them to be. You will also be able to manipulate the output via standard string operations. The Html.Raw() statements are required in order to render the HTML and scripts non-encoded.

http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/fundamentals#deferred-initialization

@{
  var widgetHtml = Html.Kendo().Editor().Name("editor").Deferred().ToString();
 
  var widgetScript = Html.Kendo().DeferredScripts(false).ToString();
}
  
@(Html.Raw(widgetHtml))
  
<script>
  // some JS code before
  @(Html.Raw(widgetScript))
  // some JS code after
</script>


Regards,
Dimo
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

0
Bill
Top achievements
Rank 1
answered on 11 Jul 2014, 08:53 AM
Hi Dimo

Using Deferred and DeferredScripts did exactly what I needed. Thanks very much!

Bill
Tags
Editor
Asked by
Bill
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Bill
Top achievements
Rank 1
Share this question
or