Kendo MVC Editor button with action

1 Answer 91 Views
Editor
Chris Womack
Top achievements
Rank 1
Chris Womack asked on 28 Feb 2022, 08:19 PM

I need to be able to add a form button in the content using the editor. Using the "view html" tool, I am able to create a button. However, I need this button to have an "onclick" property. This was possible in pervious rad editor. Is this a possibility in the current editor? 

Currently, that "onclick" property value gets stripped out when pressing "update". 

<inupt type="button" onclick="myfunction()" value="here" /> 


1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 03 Mar 2022, 02:33 PM

Hello Chris,

In it's classic mode the Editor renders the content in an iframe. To attach a click handler to an element in the iframe you can follow the approach in this SO thread, for example. That said, you can achieve the desired result the following way:

    <div id="example" class="demo-section k-content wide editor">
        @(Html.Kendo().Editor()
                  .Name("editor")
                  .HtmlAttributes(new { style = "width: 100%; height:840px" })
                  .StyleSheets(css => css
                    .Add(Url.Content("~/shared/web/editor/editorStyles.css"))
                  )
                  .Tools(tools => tools
                        .Clear()
                        .Bold().Italic().Underline()
                        .JustifyLeft().JustifyCenter().JustifyRight()
                        .InsertUnorderedList().InsertOrderedList()
                        .Outdent().Indent()
                        .CreateLink().Unlink()
                  )
                .Value(@<text>
                          <button type="button" id="btn" value="Button clicked" >Button</button> 
                </text>)
        )
    </div>
    <script>
        $(document).ready(function(){
            var editor = $("#editor").getKendoEditor();
            $(editor.body).find("#btn").click(function(){
                    alert($(this).attr("value"))
            })

        })
    </script>

 

Here is a sample REPL.

Regards,
Aleksandar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Editor
Asked by
Chris Womack
Top achievements
Rank 1
Answers by
Aleksandar
Telerik team
Share this question
or