Cancel key press

4 posts, 0 answers
  1. David
    David avatar
    16 posts
    Member since:
    Jan 2008

    Posted 01 Feb 2008 Link to this post

    Hi

    In the editor is there a way to cancel key presses? I've tried a couple of things (onkeyup return false etc). But the key pressed still gets into the text?

    Thanks
    David
  2. George
    Admin
    George avatar
    298 posts

    Posted 04 Feb 2008 Link to this post

    Hi David,

    You may try with onkeydown event because it is fired before the character is placed in the editor. I have implemented one sample project on the required functionality, please have a try and in case of some questions do not hesitate to ask.

    Sincerely yours,
    George
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Manju
    Manju avatar
    1 posts
    Member since:
    Feb 2017

    Posted 08 Aug in reply to George Link to this post

    I know this is a very old thread. But, how do we do it with latest version. Same code found in the attachment does not work with V2017 editor control. 
  4. Rumen
    Admin
    Rumen avatar
    13197 posts

    Posted 09 Aug Link to this post

    Hi,

    You can prevent the key execution with $telerik.cancelRawEvent(e);
    You can get the selected element with editor.getSelectedElement() 

    Here is an example how to disable the typing inside an A tag:

    <telerik:RadEditor ID="r1" runat="server" OnClientLoad="OnClientLoad">
        <Content>
    dasdsad <a href="http://abv.bg" >test</a> dasdassd
        </Content>
    </telerik:RadEditor>
    <script type="text/javascript">
        function OnClientLoad(editor, args) {
            editor.attachEventHandler("onkeydown", function (e) {
                          
                if (editor.getSelectedElement().tagName.toLowerCase() == "a") {
                    $telerik.cancelRawEvent(e);
                }
            });
        }
    </script>


    Regards,
    Rumen
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top