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

Unable to set readonly Html.Kendo().EditorFor(model)

7 Answers 867 Views
Editor
This is a migrated thread and some comments may be shown as answers.
swati
Top achievements
Rank 1
Veteran
swati asked on 26 Mar 2021, 03:41 AM

Hi I have a disable or read only issue with Kendo editor in my c# MVC project :

@(Html.Kendo().EditorFor(m => m.Other_Areas)
                              .Name("Other_Areas")
                              .Encode(false)
                              .Tools(tools => tools
                                  .Clear()
                                  .Bold().Italic().Underline().Strikethrough().JustifyLeft().JustifyCenter().JustifyRight().JustifyFull().InsertUnorderedList().InsertOrderedList().Outdent().Indent()
                                  .CreateLink().Unlink().InsertImage().InsertFile().SubScript().SuperScript().TableEditing().ViewHtml()
                              )
                              .HtmlAttributes(new { @class = "form-control" }))

Currently I have  @Html.TextAreaFor(m => m.Other_Areas, new { @class = "form-control" }) and "clicking "View" link calls a function called

enableControls() { document.getElementById('Other_Areas').disabled = false;} this is just working fine. Now that I have replaced with Html.Kendo().EditorFor none of the following works:

            //var cteditor = $("#Other_Areas").data("kendoEditor"),
            //editorBody = $(cteditor.body);
            //editorBody.removeAttr("contenteditable").find("a").on("click.readonly", false)
            //$($("#Other_Areas").data().kendoEditor.body).attr("contenteditable",false);
            //$("#Other_Areas").css("z-index", 2);
            //$('Other_Areas').contents().find("body").attr('contenteditable', false);
            //$('.k-editor-toolbar').hide();
            //$('#Other_Areas').attr('disabled', true);
            //$($("#Other_Areas").data().kendoEditor.body).attr("contenteditable", false);
            //$('#Other_Areas').data('kendoEditor').contentEditable(false);
            //$($('#Other_Areas').body).attr('contenteditable', false);

            //var cteditor = $("#Other_Areas").data().kendoEditor;
            //var editorBody = $(cteditor.body);
            //editorBody.attr("contenteditable", false);

            // $("#Other_Areas").data("kendoEditor").disable = true;

            //$('.k-editor textarea').each(function (idx, element) {
            //    $($(element).data("kendoEditor").body).attr("contenteditable", false);
            //});
                $(editor.body).attr('contenteditable',false);
 $('.k-editor textarea').each(function (idx, element) {
              $($(element).data("kendoEditor").body).attr("contenteditable", false);
            });

 

Currently I am using Kendo.mvc.dll version 2020.1.406.545

I tried several samples (http://dojo.telerik.com/oMaDAZ etc)  and it seems all are version specific. If I download as a seperate html/app it just works fine. Its not working in my application. I tried to add external references listed in example but my application throws multiple error stating that auto populate, date control etc are not working or Jquery not defined etc. May be because, I already have 2020 version kendo.mvc.dll locally and in addition if I add, the duplicate references leading to this error.

Please advise on how to completely disable the  Html.Kendo().EditorFor(m => m.Other_Areas) including the tools disabling like https://dojo.telerik.com/@NeliKondova/urIZAZAy 

 

Please advise. 

Many thanks,

Swati

7 Answers, 1 is accepted

Sort by
0
swati
Top achievements
Rank 1
Veteran
answered on 26 Mar 2021, 03:44 AM

I also tried adding all in <span id="Otherareaseditor">html.kendo.EditFor() <span> and tried 

$('#Otherareaseditor:input').attr("disabled", true); but still its not disabled.

I see that the data is not saved it is just that the control on the form shows all tools and editable.

0
swati
Top achievements
Rank 1
Veteran
answered on 27 Mar 2021, 04:05 AM

Can anyone please help?

The model Other_Areas saves value and returns value on the form(I can see it)

On calling this function, it says Other_Areas  'undefined' why it cant pickup up value from model when form saves and retrieves correctly?

 

0
swati
Top achievements
Rank 1
Veteran
answered on 29 Mar 2021, 06:24 AM

Hello Admins, will you please let me know if there is any solution?

Thanks

0
Martin
Telerik team
answered on 30 Mar 2021, 02:20 PM

Hello, Swati,

On this link you will find a How-To article on the matter. Could you please modify the attached solution to reproduce the issue you are experiencing? You can see that the content of the Editor cannot be edited.

Looking forward to your reply.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
swati
Top achievements
Rank 1
Veteran
answered on 30 Mar 2021, 04:16 PM

Thank you so much. This works perfect. I deleted all JS and other reference folder and reattached as per this sample. The editor body shows data now and it started working.

One last thing : when it's read-only is in full force, we want editor to be greyed out including the toolbar. I have multiple editors on the page, so I cant use the hide() option. Is there any alternatives to define or set as greyed editor and toolbox?

editorBody.removeAttr("contenteditable").find("a").on("click.readonly", false)

something simillar to $("#other_areas").prop("classname")

#classname

{  edit.color: grey !Important

}

0
swati
Top achievements
Rank 1
Veteran
answered on 30 Mar 2021, 10:06 PM

The following code worked just fine. This might help others looking for a background color change on disable control.

var oeditor = $("#Other_Areas").data("kendoEditor");

oeditor.body.style.backgroundColor = "#E9ECEF";

0
Martin
Telerik team
answered on 02 Apr 2021, 11:06 AM

Hello, Swati,

I am glad that you were able to achieve the requirement and thank you for sharing the code to do it.

Feel free to contact us whenever you have further questions.

Regards,
Martin
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
swati
Top achievements
Rank 1
Veteran
Answers by
swati
Top achievements
Rank 1
Veteran
Martin
Telerik team
Share this question
or