Disabling changes to RadEditor content without using server-side Enabled property

2 Answers 35 Views
Editor
Jeff
Top achievements
Rank 3
Bronze
Iron
Iron
Jeff asked on 01 Nov 2024, 03:25 PM | edited on 01 Nov 2024, 04:35 PM

I want to restrict the editing of a RadEditor, but I don't want to set its server-side Enabled property to false. 

Using client-side JavaScript, I'm using editor.enableEditing(false), but this still allows the user to delete or backspace to remove content.  It does not allow adding new content, nor respond to any other key.

I've tried to add an event listener for the onkeydown and keydown event to prohibit the delete and backspace keys, but that doesn't stop the user from deleting content, either. 

While debugging, I noticed that the content gets deleted prior to hitting the e.preventDefault() that is intended to stop it. 

How can I accomplish this task?


editor.enableEditing(false);
     editor.get_contentArea().onkeydown = e => {                         
         if (e.keyCode === 8 || e.keyCode === 46) { // Prevent Backspace (8) and Delete (46)
             e.preventDefault();
             e.stopPropagation();
             e.stopImmediatePropagation();
             return false;
         }
     };
                

2 Answers, 1 is accepted

Sort by
0
Jeff
Top achievements
Rank 3
Bronze
Iron
Iron
answered on 01 Nov 2024, 05:03 PM

I found the solution in this post from 2010:
Rad editor enable/disable in javascript in UI for ASP.NET AJAX | Telerik Forums

I just needed to set both the following:

editor.enableEditing(false);
editor.set_editable(false);

 

Jeff
Top achievements
Rank 3
Bronze
Iron
Iron
commented on 01 Nov 2024, 05:05 PM

Additionally, I do not need to capture the backspace and delete key.  The above two statements resolved my issue.
0
Rumen
Telerik team
answered on 02 Nov 2024, 11:44 AM

Hi Jeff,

I'm glad to hear that you've resolved your issue! I wanted to share this KB article on the subject with our fellow developers: Disabling Content Removal Using Backspace when RadEditor is disabled.

    Regards,
    Rumen
    Progress Telerik

    Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
    Tags
    Editor
    Asked by
    Jeff
    Top achievements
    Rank 3
    Bronze
    Iron
    Iron
    Answers by
    Jeff
    Top achievements
    Rank 3
    Bronze
    Iron
    Iron
    Rumen
    Telerik team
    Share this question
    or